This question already has answers here:
Facebook JS SDK's FB.api('/me') method doesn't return the fields i expect in Graph API v2.4+
                            
                                (4个答案)
                            
                    
                3年前关闭。
        

    

我正在尝试使用我的Facebook帐户登录到我的网站,但是Facebook仅给出名称和ID,不足以登录用户。在我获得完整的信息之前,例如名字,姓氏,电子邮件等。

现在由facebook提供的数据:

stdClass Object
(
    [name] => FName LName
    [id] => 236189327864097
)


跟随失败

FB.api('/me/feed?fields=gender', function(response)
code:100
fbtrace_id:"DolPwbvNcEH"
message:"(#100) Unknown fields: gender."
type:"OAuthException"


我正在使用Oauth v2.0通过Facebook将用户登录到我的网站。

我需要如下

stdClass Object
(
    [name] => FName LName
    [id] => 236189327864097,
    [gender] female
)

最佳答案

FB.api('/me', {fields: 'first_name,last_name,email'}, function(response) {
    console.log(response);
}


您需要指定要获取的字段。虽然您绝对不会在/me/feed端点中收到电子邮件,但电子邮件需要单独的权限,并且不是帖子表的字段:https://developers.facebook.com/docs/graph-api/reference/post

例如,这是如何使发布内容的用户:

FB.api('/me/feed', {fields: 'message,from'}, function(response) {
    console.log(response);
}

关于javascript - Facebook API JavaScript仅返回用户的名称和ID ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39061014/

10-09 06:53
查看更多