如何通过 Facebook API 获取生日?

How to get birthday via Facebook API?

我正在设置 Facebook 登录,并成功获取 first_nameemail 等内容。但是,我似乎无法弄清楚如何获取生日。如果我如下调用 birthday,则没有 returns.

FB.api('/me', {fields: 'birthday'}, function(response) {
  console.log(JSON.stringify(response));
})

如果我如下调用 user_birthday,我会收到此错误:"error":{"message":"(#100) Tried accessing nonexisting field (user_birthday)

FB.api('/me', {fields: 'user_birthday'}, function(response) {
  console.log(JSON.stringify(response));
})

我该怎么做?

由于您没有 post 登录代码并且没有提及权限,我想您忘记了一件重要的事情:使用 user_birthday 权限进行授权。

FB.login(function(response) {
    if (response.authResponse) {
        //user authorized the app
    }
}, {scope: 'user_birthday', return_scopes: true});

user_birthday是权限,birthday是字段名。如果仍然不起作用,则很可能没有设置生日。不确定是否需要。

例如:http://www.devils-heaven.com/facebook-javascript-sdk-login/