MakkyNZ
MakkyNZ

Reputation: 2255

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

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?

Upvotes: 1

Views: 6229

Answers (2)

Tobi
Tobi

Reputation: 31489

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}

Upvotes: 0

smalu
smalu

Reputation: 441

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

Upvotes: 3

Related Questions