Get ALL User Friends Using Facebook Graph API - Android

David picture David · May 25, 2014 · Viewed 104.3k times · Source

I'm trying to get all friends, of a user that logged into my application.

I can't use this API [friends]:

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends

Because this API only returns any friends who have used the app making the request.

So I found this API [friendlist]:

https://developers.facebook.com/docs/graph-api/reference/v2.0/friendlist

Followed this answer, I got the friendlist list.

But I'm getting empty list when trying to get friendlist's members:

new Request(
            session,
            "/2692926356774/members",
            null,
            HttpMethod.GET,
            new Request.Callback()
            {
                public void onCompleted(Response response)
                {
                    /* handle the result */
                    Log.e(LOG_TAG,"Members: " + response.toString());
                }
            }
    ).executeAsync();

2692926356774 is my Acquaintances list id, I tried few other id's with the same result.

Answer

Simon Cross picture Simon Cross · May 29, 2014

In v2.0 of the Graph API, calling /me/friends returns the person's friends who also use the app.

In addition, in v2.0, you must request the user_friends permission from each user. user_friends is no longer included by default in every login. Each user must grant the user_friends permission in order to appear in the response to /me/friends. See the Facebook upgrade guide for more detailed information, or review the summary below.

The /me/friendlists endpoint and user_friendlists permission are not what you're after. This endpoint does not return the users friends - its lets you access the lists a person has made to organize their friends. It does not return the friends in each of these lists. This API and permission is useful to allow you to render a custom privacy selector when giving people the opportunity to publish back to Facebook.

If you want to access a list of non-app-using friends, there are two options:

  1. If you want to let your people tag their friends in stories that they publish to Facebook using your App, you can use the /me/taggable_friends API. Use of this endpoint requires review by Facebook and should only be used for the case where you're rendering a list of friends in order to let the user tag them in a post.

  2. If your App is a Game AND your Game supports Facebook Canvas, you can use the /me/invitable_friends endpoint in order to render a custom invite dialog, then pass the tokens returned by this API to the standard Requests Dialog.

In other cases, apps are no longer able to retrieve the full list of a user's friends (only those friends who have specifically authorized your app using the user_friends permission).

For apps wanting allow people to invite friends to use an app, you can still use the Send Dialog on Web or the new Message Dialog on iOS and Android.