How to get birthday via Facebook API?

你说的曾经没有我的故事 提交于 2021-02-07 06:26:08

问题


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?


回答1:


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.com/facebook-javascript-sdk-login/



来源:https://stackoverflow.com/questions/34927836/how-to-get-birthday-via-facebook-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!