20

I am trying to retrieve comments and likes for specific posts through Facebook's opengraph API. While I do get some information back, it does not always match the comments/likes count mentioned in the post. I guess this can be attributed to the access permissions of the token I'm using. However, I have noticed that results vary depending on the request limit I use, and sometimes I also get duplicate entries between requests.

For example, post 10376464573_150423345118848 has about 14000 likes as of this writing, but I can only retrieve a maximum of around 5000. With the default limit of 25 I can get up to 3021 likes. A value of 100 gives 4501, while limits of 1000, 2000, 3000 and 5000 all return the same number of likes, 4959 (the absolute values don't make too much sense of course, they are just there for comparison).

I have noticed similar results on a smaller scale for comments.

I'm using a simple python script to fetch pages. It goes through the data following the pagination links provided by Facebook, writing each page retrieved to a separate file. Once an empty reply is encountered it stops.

With small limits (e.g. the default of 25), I notice that the number of results returned is monotically decreasing as I go through the pagination links, which seems really odd.

Any thoughts on what could be causing this behavior and how to work around it?

mpitid
  • 453
  • 1
  • 5
  • 10
  • I think there is a limit by 5000 objects. [Facebook's 5000 Post API Limit][1] [Breaking the 5000 object limit in Facebook API][2] [1]: http://stackoverflow.com/questions/10422186/facebooks-5000-post-api-limit [2]: http://stackoverflow.com/questions/3452018/breaking-the-5000-object-limit-in-facebook-api – N. Mauchle Sep 05 '15 at 12:18
  • There is no 5000 limit, you can easily retrieve all likes (currently ca. 20.000) for that Lady Gaga post – lars.schwarz Sep 30 '15 at 21:27

2 Answers2

1

If you are looking for a list of the names of each and every like / comment on a particular post I think you will run up against the API limit (even with pagination).

If you are merely looking for an aggregate number of likes, comments, shares, or link clicks, you'll want to simply use the summary=true param provided in the posts endpoint. Kind of like this:

try:
    endpoint = 'https://graph.facebook.com/v2.5/'+postid+'/comments?summary=true&access_token='+apikey
    response = requests.get(endpoint)
    fb_data = response.json()
    return fb_data

You can also retrieve all of the posts of any particular page and their summary data points:

{page_id}/posts?fields=message,likes.limit(1).summary(true)
1

You can retrieve comments and like count or other information of a particular post using url or api below.

https://graph.facebook.com/{0}/comments?access_token={1}&limit={2}&fields=from,message,message_tags,created_time,id,attachment,like_count,comment_count,parent&order=chronological&filter=stream'.format(post_id,access_token,limit)

As here order specified as chronological, you need to use after parameter as well in the same url whose value one can get in paging.cursor.after section of the first response.

Tom Sabel
  • 3,935
  • 33
  • 45