Search code examples
javafacebook-graph-apirestfb

Getting all friends from facebook using restfb


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


Solution

  • 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.