0

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

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

I get the following logged-in user 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}!

It is possible to get user's age and birthday to verify if user is 18 or older? If yes, how can I do that?

Gargaroz
  • 313
  • 9
  • 28
O Connor
  • 4,236
  • 15
  • 50
  • 91

2 Answers2

0

You need to configure your Facebook "app" (API key) to request permission to access that profile data.

Ted Nyberg
  • 7,001
  • 7
  • 41
  • 72
  • I have red the Facebook Docs but still could not find the information about configuring app to request permission to get the user's birthday. Do you know how? – O Connor Jun 10 '15 at 08:22
0

Use any available public profile information before asking for a permission. For example, there is an age_range field included in the public profile for anyone who installs your app. This field may be sufficient for your app instead of requesting user_birthday permission.

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

-- UPDATE --

You'll have to explicitly tell the API that you need age_range. The user's age range may 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 person's age. enum{17, 20, or empty}.

  • min (unsigned int32) The lower bounds of the range for this person's age. enum{13, 18, 21} Default

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

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

Buzz
  • 370
  • 2
  • 6
  • de public profile includes on A person's public profile refers to the following properties on the user object by default: id,name,first_name,last_name,link,gender,locale timezone updated_time verified. How can I get the age_range property? – O Connor Jun 09 '15 at 15:18
  • You'll have to explicitly tell the API that you need age_range. i have updated the answer with example code and reference to age field documentation. – Buzz Jun 09 '15 at 15:50
  • How can I get user_birthday? – O Connor Jun 10 '15 at 09:01
  • queried field age_range (example above) will tell you exactly if your user is older than 18 years (as you have asked in your 1st question above). this information you will get in reponse field age_range->min (e.g. 21) = 21+ years old... if you really need exactly to know user_birthday, then you need to ask for this permission but this information very few people will grant you. use rather the public_profile information as proposed (FB.api("/me?fields=age_range", ...) ... – Buzz Jun 10 '15 at 17:14