[英]Get logged-in user profile information with Facebook Login
我在我的網站上將Facebook Login與JavaScript SDK集成在一起。 具有以下功能:
FB.api('/me', function(response) {
console.log(JSON.stringify(response));
});
我得到以下登錄的用戶信息:
{"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}!
是否可以獲取用戶的年齡和生日,以驗證用戶是否年滿18歲? 如果是,我該怎么做?
您需要配置Facebook“應用”(API密鑰)以請求訪問該配置文件數據的權限。
在申請許可之前,請使用任何可用的公共資料信息。 例如,公開個人資料中包含一個age_range字段,用於安裝您的應用的任何人。 此字段可能足以滿足您的應用程序的需求,而不是請求user_birthday權限。
在此處了解更多信息https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-public_profile
-更新-
您必須明確告知API您需要age_range。 用戶的年齡范圍可以是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 */
}
}
);
這應該返回類似:
{
"age_range": {
"min": 21
},
"id": <user_id>
}
領域
max (無符號int32)此人年齡范圍的上限。 枚舉{17、20或為空}。
min (無符號int32)此人年齡范圍的下限。 枚舉{13,18,21}默認
這里的年齡范圍字段文檔https://developers.facebook.com/docs/graph-api/reference/age-range/
如何在此處使用字段文檔https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#fields
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.