[英]Get logged-in user profile information with Facebook Login
I am integrating Facebook Login with JavaScript SDK on my website. 我在我的网站上将Facebook Login与JavaScript SDK集成在一起。 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? 是否可以获取用户的年龄和生日,以验证用户是否年满18岁? 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.
例如,公开个人资料中包含一个age_range字段,用于安装您的应用的任何人。 This field may be sufficient for your app instead of requesting user_birthday permission.
此字段可能足以满足您的应用程序的需求,而不是请求user_birthday权限。
read more here https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-public_profile 在此处了解更多信息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. 您必须明确告知API您需要age_range。 The user's age range may be 13-17, 18-20 or 21+.
用户的年龄范围可以是13-17、18-20或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. max (无符号int32)此人年龄范围的上限。 enum{17, 20, or empty}.
枚举{17、20或为空}。
min (unsigned int32) The lower bounds of the range for this person's age. min (无符号int32)此人年龄范围的下限。 enum{13, 18, 21} Default
枚举{13,18,21}默认
age range field documentation here https://developers.facebook.com/docs/graph-api/reference/age-range/ 这里的年龄范围字段文档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 如何在此处使用字段文档https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#fields
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.