如何通过 Facebook API 获取生日?
我正在设置 Facebook 登录,并且成功获取了诸如 first_name
、email
等内容.但是,我似乎不知道如何获得生日.如果我调用 birthday
如下,则没有任何返回.
I am setting up a Facebook login, and am successfully getting things like first_name
, email
, etc. However, I cannot seem to figure out how to get birthday. If I call for birthday
as below, nothing returns.
FB.api('/me', {fields: 'birthday'}, function(response) {
console.log(JSON.stringify(response));
})
如果我按如下方式调用 user_birthday
,我会收到此错误:"error":{"message":"(#100) 尝试访问不存在的字段 (user_birthday)
If I call user_birthday
as below, I get this error: "error":{"message":"(#100) Tried accessing nonexisting field (user_birthday)
FB.api('/me', {fields: 'user_birthday'}, function(response) {
console.log(JSON.stringify(response));
})
我该怎么做?
由于您没有发布登录代码,也没有提及权限,我想您忘记了一件重要的事情:使用 user_birthday
进行授权> 许可.
Since you did not post your login code and you did not mention permissions, i assume you forgot one important thing: Authorizing with the user_birthday
permission.
FB.login(function(response) {
if (response.authResponse) {
//user authorized the app
}
}, {scope: 'user_birthday', return_scopes: true});
user_birthday
是权限,birthday
是字段的名称.如果它仍然不起作用,那么很可能没有设置生日.不确定是否需要.
user_birthday
is the permission, birthday
is the name of the field. If it still doesn´t work, then there is most likely no birthday set. Not sure if it is required.