简体   繁体   English

如何使用restfb获取用户的详细信息?

[英]How to get the details of the user using restfb.?

我正在尝试使用restfb获取我的个人资料的姓氏,但是每次用户名返回为null时,我已经拥有了访问令牌和权限。我想JSon对象传递会出现一些问题,如何传递json对象到javabean,然后再检索?

This happens when the access token you provided doesn't have the correct permissions to access the data. 当您提供的访问令牌没有正确的访问数据权限时,就会发生这种情况。 Best way to check this is by using the facebook graph API interface; 最好的检查方法是使用facebook graph API接口。 noting the version. 注意版本。 https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me&version=v2.4 https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me&version=v2.4

FacebookClient fbClient = new DefaultFacebookClient(accessToken, Version.VERSION_2_4);
User me = fbClient.fetchObject("me", User.class, Parameter.with("fields", "email,first_name,last_name,gender"));

Note: Your FB.login function must contain the correct scope for fields you want to access. 注意: FB.login函数必须包含要访问的字段的正确范围。

FB.login(function(response) {

           ...

        }, {scope: 'email'});

Here is the code snippet 这是代码片段

FacebookClient facebookClient = new DefaultFacebookClient("register a facebook application with required permissions, get that application token and paste here");

User user = facebookClient.fetchObject("me", User.class);

Connection<User> myFriends = facebookClient.fetchConnection("me/friends", User.class);

for(User friend:myFriends.getData())
{
    Connection<Page> myMovies = facebookClient.fetchConnection(friend.getId() + "/movies", Page.class);

    content = content + "Name: " + friend.getName();
    for(Page page:myMovies.getData())
    {
        content = content  + "\n" + "Movies: " + page.getName() + "\n";
    }
}

In this example your application needs "friends_likes" permission. 在此示例中,您的应用程序需要“ friends_likes”权限。

Hope this helps. 希望这可以帮助。

This works for me: 这对我有用:

FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
User user = facebookClient.fetchObject("me", User.class);
out.println("Last name: " + user.getLastName());

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

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