小编典典

JavaScriptJS SDK的FB.api('/ me')方法未返回我在Graph API v2.4 +中期望的字段

javascript

我正在尝试使用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' }
  );
}

这是激活它的按钮

<a id="fb-login" href="#" onclick="facebookLogin()"></a>

阅读 540

收藏
2020-04-23

共1个答案

小编典典

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

例如

FB.api('/me', 'get', { access_token: token, fields: 'id,name,gender' }, function(response) {
    console.log(response);
});
2020-04-23