2
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);

System.out.println("Count of my friends- " + myFriends.getData().size());

I am unable to get the friends data(name and other fields). It is displaying me count=0. I have given the permission for user_friends also. Infact in Graph API Explorer I tried graphAPI as me/friends It is displaying me

 {
      "data": [
      ],
      "summary": {
        "total_count": 463
      }
    }

Please help! Thanks in advance

anjali
  • 147
  • 13

3 Answers3

1

The problem lies with your access token, as I have tried the code snippet you posted with my own access token and it prints the correct count of my friends.

You can debug your access token at the following link: https://developers.facebook.com/tools/debug/access_token/

If this doesn't solve your problem please reply with the access token info that you get from debugging your access token at that link.

alexoakley1
  • 565
  • 4
  • 11
0

myFriends.getTotalCount() would give you what you are looking for.

Guy Sela
  • 173
  • 1
  • 9
0

You can only retrieve your friends who are using the same app. Otherwise, there is no way to get your friend name. Only friends total_count will be returned if you have a permission like this:

ScopeBuilder permissions = new ScopeBuilder();
permissions.addPermission(FacebookPermissions.USER_FRIENDS);
DefaultFacebookClient facebookClient = new DefaultFacebookClient(Version.VERSION_3_0);
String loginURL = facebookClient.getLoginDialogUrl(Constants.APP_ID, Constants.REDIRECT_URL, permissions);
Roshana Pitigala
  • 8,437
  • 8
  • 49
  • 80
tony hu
  • 81
  • 1
  • 3