Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get birthday via Facebook API?

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?

like image 934
j_d Avatar asked Jan 21 '16 15:01

j_d


People also ask

Can I use Facebook API for free?

The Graph API is free to use, for all applicable use cases. Rate Limiting applies though, > developers.facebook.com/docs/graph-api/advanced/rate-limiting There is no way to “pay” or > otherwise get those limits raised for normal 3rd party apps.

Does Facebook allow API?

The Facebook API allows your app — and your app users — to access and manage content in their Facebook Group. With this API, you can let people publish content from your app to their Group.

How do I see birthdays on Facebook from non friends?

Using the search bar, type birthdays. Select the Birthdays (see upcoming birthdays) option that appears at the top.


1 Answers

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/

like image 112
andyrandy Avatar answered Oct 17 '22 12:10

andyrandy