简体   繁体   English

使用restfb从facebook获取所有朋友

[英]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.它显示我计数 = 0。 I have given the permission for user_friends also.我也给了 user_friends 权限。 Infact in Graph API Explorer I tried graphAPI as me/friends It is displaying me事实上,在 Graph API Explorer 中,我以我/朋友的身份尝试过 graphAPI 它正在显示我

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

Please help!请帮忙! Thanks in advance提前致谢

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/您可以通过以下链接调试您的访问令牌: 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.如果这不能解决您的问题,请回复您通过在该链接上调试访问令牌获得的访问令牌信息。

myFriends.getTotalCount() 会给你你正在寻找的东西。

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:如果你有这样的权限,只会返回朋友 total_count :

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM