最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get birthday via Facebook API? - Stack Overflow

programmeradmin6浏览0评论

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

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

How do I do this?

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

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

How do I do this?

Share Improve this question edited Dec 12, 2016 at 14:05 andyrandy 74k9 gold badges114 silver badges132 bronze badges asked Jan 21, 2016 at 15:33 j_dj_d 3,08210 gold badges55 silver badges96 bronze badges 2
  • Are you sure that every user has entered a birthday ? – Fer To Commented Jan 21, 2016 at 15:37
  • Does birthday_date work? – user5325596 Commented Jan 21, 2016 at 15:38
Add a ment  | 

1 Answer 1

Reset to default 16

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 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.

For example: http://www.devils-heaven./facebook-javascript-sdk-login/

发布评论

评论列表(0)

  1. 暂无评论