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+
问题描述
{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:
- https://developers.facebook.com/docs/apps/changelog#v2_4
- https://developers.facebook.com/docs/javascript/reference/FB.api
声明性字段
尝试提高移动网络上的节点和节点的性能.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:
- https://developers.facebook.com/docs/apps/changelog#v2_4
- https://developers.facebook.com/docs/javascript/reference/FB.api
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屋!