使用Facebook登录获取登录的用户个人资料信息

时间:2015-06-09 10:50:16

标签: javascript facebook login

我正在我的网站上集成Facebook登录和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岁?如果是,我该怎么做?

2 个答案:

答案 0 :(得分:0)

您需要配置您的Facebook" app" (API密钥)请求访问该配置文件数据的权限。

答案 1 :(得分:0)

在要求许可之前,请使用任何可用的公开个人资料信息。例如,安装您的应用的任何人都可以在公开个人资料中找到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 (unsigned int32)此人年龄范围的上限。枚举{17,20或空}。

  • min (unsigned int32)此人年龄范围的下限。 enum {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