12

My application(game) has been running on Facebook for some time. I start by requesting a friends list via the graph API call: my-uid/friends asking for user name and profile pic.

Normally I get back a list of all my friends up to a few thousand, until it starts putting friends on to the next page. Which is nice as most of my users get friends in 1 call.

Suddenly however, and with no changes to the app. about 40 minutes ago (18:40 Tuesday (PDT) - 2nd May 2012) I started getting responses with only 25 friends per 'page'!

I can still get my whole friends list using multiple calls, but the game is not currently set up to do that properly. Can anyone tell me why the sudden change? Anyone else seen similar problems and how do I get the list to give me up to 5000 friends per page like it used to.

Reproducible using the Graph API Explorer

Bart
  • 19,692
  • 7
  • 68
  • 77
Paul Naylor
  • 197
  • 1
  • 1
  • 8

6 Answers6

19

I don't know what else to tell you; perhaps the default number returned has changed, but when I try, a call to /me/friends?limit=5000 returns the full list for me (but my friends list is >500 and < 1000 , so maybe it cuts off somewhere along the way)

(Side note: the average number of friends has been found to be ~190 so presumably most users will have less than 500 anyway, and having to page above 500 would be an edge case

Igy
  • 43,710
  • 8
  • 89
  • 115
  • Thanks Igy. Yes, I suspect the default number has changed - a little warning would have been nice. I've got the limit explicitly mentioned now and it works fine. – Paul Naylor May 02 '12 at 03:57
  • It may be reverted tomorrow for just that reason; these things are usually announced in advance even if they shouldn't break apps – Igy May 02 '12 at 03:59
  • `/me/friends?limit=5000` does not work at least from today on. – Ionut Necula Sep 27 '17 at 09:28
  • I just tried it now and `/me/friends?limit=5000` is still working for me on iOS here at the beginning of 2018. If I remove limit=5000 I only get back 25 as expected. – ToddH Jan 22 '18 at 21:09
4

In SDK 4.7 you need to pass in a bundle with the number of friends you want to return, I have set it to 5000 as this is the maximum number of friends you can have on Facebook.

You also need to set up your app as a game in the facebook dev console and use invitable friends to get a full friends list

Create your bundle

Bundle bundle = new Bundle();

Add params to your bundle

bundle.putInt("limit", 5000);

Then pass it in to your GraphRequest

new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/me/invitable_friends",
            bundle,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                public void onCompleted(GraphResponse response) {
                   //Do something with the response
                }
            }
    ).executeAsync();
MichaelStoddart
  • 5,571
  • 4
  • 27
  • 49
3

It seems that facebook changed its limit to 25 results in other api calls too (feed, posts, friends, etc), if you request friends without parameters the JSON response shows the following:

"paging": {
    "next": "https://graph.facebook.com/USER_ID/friends?format=json&limit=25&offset=25&__after_id=LAST_ID"
}

Anyway you could/should always set limit & offset parameters to prevent this kind of things, limit = 0 will return all your friends list.

https://graph.facebook.com/USER_ID/friends?limit=0

If you are only requesting friends from a normal user the maximum number allowed is 5,000 so the limit should could be either 0 or 5,000 if you are requesting info from a facebook page or other kind of api calls like posts or feed this limit could increase or decrease.

(Update) Facebook fixed this bug so setting limit to 0 returns 0 friends, you should set a positive limit, thanks Dinuz

German Gil
  • 486
  • 3
  • 5
  • 2
    Dear German, the limit=0 is a bug, and with the October 2013 Breaking Changes they are removing it. Using limit=0 and be compliant with the new rules will return 0 friends. I think for now the best option is to set it at limit=5000 (after that you can't anyway have friends, and they just need to follow you). – Dinuz Jul 17 '13 at 22:19
  • Yep it was a bug, my answer was from 2012 and the change took place at the end of 2013 I have updated the answer, thanks – German Gil Jan 07 '14 at 17:44
2

I think the best thing you can do is to add limit=5000 parameter as Igy says.
However I posted a bug report since this change wasn't noticed or described in the document.

Oklahomer
  • 896
  • 9
  • 24
1

The number of results returned from the /v2.2/me/friends endpoint now defaults to 25.

Friend list now only returns friends who also use your app: The list of friends returned via the /me/friends endpoint is now limited to the list of friends that have authorized your app.

See Facebook changes Facebook API change log

Anish
  • 11
  • 5
1

If you are using GraphRequest() (e.g. in React Native), you can put it directly in the string field, like so :

new GraphRequest(
  '/me',
  {
    accessToken,
    parameters: {
        fields: {
          string: 'id,email,first_name,last_name,friends.limit(5000)'
        }
    }
    ...
gowithefloww
  • 2,211
  • 2
  • 20
  • 31