Facebook JS SDK的FB.api('/ me')方法不会返回我在Graph API v2.4 +中预期的字段

Jua*_*tes 32 javascript facebook

我正在尝试使用Facebook api获取一些基本信息,但到目前为止我只获得了用户的名字和ID.如在{ name: "Juan Fuentes", id: "123456" }

我需要获得电子信息,如电子邮件,名字,姓氏和生日

这是我的js代码

function facebookLogin() {
  FB.login(function(response) {
    var token = response.authResponse.accessToken;
    var uid = response.authResponse.userID;
    if (response.authResponse) {
      FB.api('/me', 'get', { access_token: token }, function(response) {
        console.log(response);
      });

      FB.api('/'+uid, 'get', { access_token: token }, function(response) {
        console.log(response);
      });
    }
  },
  { scope: 'public_profile' }
  );
}
Run Code Online (Sandbox Code Playgroud)

这是激活它的按钮

<a id="fb-login" href="#" onclick="facebookLogin()"></a>
Run Code Online (Sandbox Code Playgroud)

Tob*_*obi 55

自Graph API v2.4起,您需要手动指定每个字段:

声明性字段
要尝试提高移动网络的性能,v2.4中的节点和边缘要求您明确请求GET请求所需的字段.例如,GET /v2.4/me/feed默认不再包含喜欢和评论,但GET /v2.4/me/feed?fields=comments,likes将返回数据.有关更多详细信息,请参阅有关如何请求特定字段的文档.

例如

FB.api('/me', 'get', { access_token: token, fields: 'id,name,gender' }, function(response) {
    console.log(response);
});
Run Code Online (Sandbox Code Playgroud)