Skip to content
nov edited this page Jun 18, 2013 · 2 revisions

Posts and Comments

Posts

GET

# single post
FbGraph::Post.fetch(POST_ID, :access_token => ACCESS_TOKEN)

# posts by me
FbGraph::User.me(ACCESS_TOKEN).posts

# posts by a page
FbGraph::Page.new(PAGE_ID, :access_token => ACCESS_TOKEN).posts

POST

When generating a new post, use `feed` connection, instead of `posts`.

# post as an user
FbGraph::User.me(ACCESS_TOKEN).feed!(
  :message => 'hello world'
)

# post as a page
FbGraph::Page.new(PAGE_ID, :access_token => ACCESS_TOKEN).feed!(
  :message => 'hello world'
)

DELETE

FbGraph::Post.new(POST_ID, :access_token => ACCESS_TOKEN).destroy

Comments

GET

# post comments
FbGraph::Post.new(POST_ID, :access_token => ACCESS_TOKEN).comments

# comment replies (comment replies are also comment objects)
FbGraph::Comment.new(COMMENT_ID, :access_token => ACCESS_TOKEN).comments

# fetch "can_comment" property, specify "fields" option
comment = FbGraph::Comment.fetch(COMMENT_ID, :access_token => ACCESS_TOKEN, :fields => "can_comment")
comment.can_comment

POST

# post a comment on a post
post = FbGraph::Post.new(POST_ID, :access_token => ACCESS_TOKEN)
post.comment!(
  :message => 'hello'
)

# reply to a comment
comment = FbGraph::Comment.fetch(COMMENT_ID, :access_token => ACCESS_TOKEN, :fields => "can_comment")
if comment.commentable?
  comment.reply!(
    :message => "Hello!",
    :access_token => ACCESS_TOKEN
  )
end

DELETE

FbGraph::Comment.new(COMMENT_ID, :access_token => ACCESS_TOKEN).destroy
Clone this wiki locally