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?
您需要配置Facebook“应用”(API密钥)以请求访问该配置文件数据的权限。
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.