Facebook JS SDK 的 FB.api('/me') 方法不会返回我在 Graph API v2.4+ 中期望的字段 [英] Facebook JS SDK's FB.api('/me') method doesn't return the fields I expect in Graph API v2.4+

查看:35
本文介绍了Facebook JS SDK 的 FB.api('/me') 方法不会返回我在 Graph API v2.4+ 中期望的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to get some basic information using Facebook api, but so far I only get the user's name and id. As in { name: "Juan Fuentes", id: "123456" }

我需要获取更多电子信息,例如电子邮件、名字、姓氏和生日

I need to get mor einformation, like email, first name, last name and birthday

这是我的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>

推荐答案

Graph API v2.4 开始需要手动指定每个字段:

You need to manually specify each field since Graph API v2.4:

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

Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

例如

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

这篇关于Facebook JS SDK 的 FB.api('/me') 方法不会返回我在 Graph API v2.4+ 中期望的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆