Facebook Graph API - get latest comments

I'm trying to parse fb feed to find new comments. First I get posts list by this url http://graph.facebook.com/2.0/page_id/posts. Then I get comments by http://graph.facebook.com/2.0/page_id/post_id/comments for each post. I found that I can use batch_requests and http://graph.facebook.com/2.0/page_id/posts?fields=comments. But I want to ask:

  1. Can I get and parse only new comments? Not for all existing posts. Can I get response sorted by latest comments?
  2. If no, what should I do in next case - Comment for post isn't included in fb/posts because this post created 250 posts before?

P.S. FQL is not good solution because it is deprecated.

Upvotes: 4

Views: 5361

Answers (2)

Tama
Tama

Reputation: 1715

You can specify an order of reverse_chronological to get the newest comments first. It's not documented but seems to work from v2.0 on.

i.e. Get all post comments w/ newest first

[post_id]/comments?filter=stream&order=reverse_chronological

Upvotes: 7

andyrandy
andyrandy

Reputation: 73984

  1. No, you can not get new comments only and you need to do the sorting on your own too.
  2. Store the comments in a database. You can go through all comments, the new ones should be the first ones, check the comment ID in your database. If the comment ID is already in the database, stop getting more comments. Alternatively, you could also just store the latest comment ID somewhere instead of all comments.

Upvotes: 5

Related Questions