How to get most liked, commented and shared posts from Facebook's API

北城余情 提交于 2019-12-06 14:33:52

问题


I'm trying to get some figures from Facebook telling me which posts have the most likes, comments and shares for a given Facebook page and within a given date range.

I can get these figures if I query the API to get all the individual posts and loop through them in my own code, but I'm often getting an error from the API "600 calls per 600 seconds" rate limit error from them, because I'm making a call for each post. I've tried using FB's batch graph requests but this doesn't reduce the likelyhood of getting that error.

Is there a way to do this so that I don't need to make so many calls?


回答1:


Yes, you have to make individual API calls. Batch api requests are counted as normal requests [0]:

For example, a batch of 10 API calls will count as 10 calls and each call within the batch contributes to CPU resource limits in the same manner.

My tips:

  • make graph api call server-side and store results in a database
  • make some delays between each call
  • you can increase your request limit by making some delays between each
  • use multiple extended page access tokens [1] and pick random for each call
  • make calls without sdk - you can make simple GET request with eg. curl to https://graph.facebook.com/post_id?access_token=access_token

[0] - https://developers.facebook.com/docs/graph-api/making-multiple-requests/#limits

[1] - https://stackoverflow.com/a/17234650/1587309




回答2:


You can use FQL (which will be available at least until April 30th 2016) to achieve this in one call:

select post_id, comment_info.comment_count, like_info.like_count, share_info.share_count from stream where source_id={PAGE_ID}

Just replace {PAGE_ID} with the actual Page ID. You can also run this via a Page Access Token with the read_stream permission.

If you want just the Page's posts, add the following to the FQL query:

and actor_id={PAGE_ID}


来源:https://stackoverflow.com/questions/24151096/how-to-get-most-liked-commented-and-shared-posts-from-facebooks-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!