Get registered user profile information using Facebook Login

I integrate Facebook Login with the JavaScript SDK on my website. With the following function:

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

I get the following login information:

 {"id":"xxxx","email":"xxxx","first_name":"xxxx","gender":"xxxx","last_name":"xxxx","link":"https://www.facebook.com/xxxxx","locale":"xxx","name":"xxxx","timezone":xx,"updated_time":"xxxxx","verified":true}! 

Can I set the user's age and birthday to find out who is over 18? If so, how can I do this?

0
source share
2 answers

You need to configure the Facebook application (API) to request permission to access this profile data.

0
source

Use any publicly available information before requesting permission. For example, there is an age_range field included in the general profile for everyone who installs your application. This field may be sufficient for your application, and not for user_birthday request.

more details here https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-public_profile

- UPDATE -

You need to explicitly tell the API that you need age_range. The age of the user can be 13-17, 18-20 or 21+.

 /* make the API call v.2.3 */ FB.api( "/me?fields=age_range", function (response) { if (response && !response.error) { /* handle the result */ } } ); 

This should return something like:

 { "age_range": { "min": 21 }, "id": <user_id> } 

FIELDS

  • max (unsigned int32) The upper bounds of the range for this age. enum {17, 20 or empty}.

  • min (unsigned int32) Lower range limits for this age. enum {13, 18, 21} Default

age range documentation here https://developers.facebook.com/docs/graph-api/reference/age-range/

how to use docs fields here https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#fields

0
source

All Articles