Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call more than 100 statuses with Facebook API?

I'm building a Facebook application and I want it to be able to read all the user's statuses from the past year. When I make the API call, I can only retrieve the first 100 statuses no matter what I set the limit to.

Here's the URL I'm using to make the call: https://graph.facebook.com/me/statuses?limit=100&access_token=...

When I set the limit lower, it shows fewer statuses (proving that the limit argument works). When I set the limit higher, it only gives me the first 100. When I use 'since', it still only gives me 100.

When I use the 'next' url it gives me, I see no data past the first 100 statuses.

I know it's possible to get much more than that because of applications such as My Year In Status

like image 811
Sean Gransee Avatar asked Jan 12 '12 23:01

Sean Gransee


2 Answers

It does work. You must use both the limit and offset query parameters. The limit parameter sets the batch size. The offset parameter sets the position in the user's all-time status collection. Without specifying the offset parameter, Facebook defaults it to zero, which is why you keep seeing the same dataset.

For the 1st batch of 100 statuses, set limit to 100 and offset to 0.
For the 2nd batch of 100 statuses, set limit to 100 and offset to 100.
For the 3rd batch of 100 statuses, set limit to 100 and offset to 200.
For the 4th batch of 100 statuses, set limit to 100 and offset to 300.
And so on...

Keep iterating until you get an empty dataset:

{
   "data": []
}
like image 163
Bill Paetzke Avatar answered Sep 28 '22 16:09

Bill Paetzke


I've verified using the Graph API explorer that the pagination is not working as you have described. Log it as a bug with Facebook at: https://developers.facebook.com/bugs and post the bug # here.

EDIT

Per the bug closure, the 100 limit is By Design and you won't get more than that, meaning that Facebook has made a conscious business decision to limit the amount of data it has to store, process, and serve from the Graph API. It costs money to do so and since the API is free to use, I can't argue with them. However, if I was paying for it, then hell yes I kick and scream all the way down the road.

like image 23
DMCS Avatar answered Sep 28 '22 17:09

DMCS