2

I'm trying to retrieve a list of all friends, but it always returns a zero size list... No exception nor fail...

I'm using following permissions:

Permission[] permissions = new Permission[] {
            Permission.BASIC_INFO,
            Permission.READ_FRIENDLISTS
    };

and I'm using following code:

private static OnFriendsListener mOnFriendsListener = new OnFriendsListener()
{
    @Override
    public void onComplete(List<Profile> friends)
    {
        L.d(FacebookHelper.class, "OnFriendsListener::onComplete");
        BusProvider.getInstance().post(new FacebookEvent(Type.Friends, friends));
    }

    @Override
    public void onException(Throwable throwable)
    {
        L.d(FacebookHelper.class, "OnFriendsListener::onException");
        L.e(FacebookHelper.class, new Exception(throwable));
    }

    @Override
    public void onThinking()
    {
    }

    @Override
    public void onFail(String reason)
    {
        L.d(FacebookHelper.class, "OnFriendsListener::onFail");
    }
};

public static void getFriends(SimpleFacebook simpleFacebook)
{
    PictureAttributes pictureAttributes = Attributes.createPictureAttributes();
    pictureAttributes.setType(PictureType.SMALL);

    Properties properties = new Properties.Builder()
            .add(Properties.ID)
            .add(Properties.FIRST_NAME)
            .add(Properties.LAST_NAME)
            .add(Properties.PICTURE, pictureAttributes)
            .add(Properties.BIRTHDAY).build();

    simpleFacebook.getFriends(properties, mOnFriendsListener);
}

Can anybody help me out with this problem?

prom85
  • 16,896
  • 17
  • 122
  • 242
  • I hate to say it, but I think this is effectively the same problem as http://stackoverflow.com/questions/23417356 In particular, this might mean the problem might not be soluble; from the answer to that question: "In v2.0 of the Graph API, calling /me/friends returns the person's friends who also use the app … 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). This has been confirmed by Facebook as 'by design'." – Owen Blacker Jun 04 '14 at 15:29

1 Answers1

2

Are you using the Facebook SDK for Android v3.14? If so, make sure to request the "user_friends" permission which lets the app read friends who also logged into the app with Facebook.

Note: v3.14 uses Graph API 2.0 by default. In that version of the API, GET /me/friends returns friends who logged into the app with Facebook.

If you're building a feature to tag friends in a post, take a look at the Taggable Friends API:

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

More info on the 2.0 changes is here:

https://developers.facebook.com/docs/apps/changelog#v2_0_login

Eddie O'Neil
  • 318
  • 1
  • 4
  • at the moment, the library works only with 3.8 and that's what I'm using... Btw, I don't want to read a list of friends that are logged in with the app, but just a list of all friends... I want to make a image sync tool for my android contacts... – prom85 May 07 '14 at 17:00
  • 1
    If you created your app after 04/30/2014, then you're using Graph API 2.0, and you should use v3.14 since v3.8 is not compatible with Graph API 2.0. In Graph API 2.0, you can no longer get a list of all friends, only friends who also use the app. – Ming Li May 08 '14 at 21:04