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+

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

问题描述

我正在尝试使用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-loginhref =#onclick =facebookLogin()>< / a> 


解决方案

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






声明性字段

尝试提高移动网络上的节点和节点的性能.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(响应);
});


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

This is my js code

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' }
  );
}

And this is the button that activates it

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

解决方案

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

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.

E.g.

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天全站免登陆