简体   繁体   English

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

[英]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.

相关问题 在 Keycloak 中获取登录用户的角色 - Get Roles of logged-in User in Keycloak 区分未登录的Facebook用户与已登录的Facebook用户,但尚未授权我们的应用程序 - Differentiate a not-logged-in Facebook user vs. a logged-in Facebook user but not authorize our application yet SharePoint-使用ASP获取登录用户,使用JavaScript进行操作? - SharePoint - get logged-in user with ASP, manipulate with javascript? Javascript-使用Facebook登录,成功登录后显示用户的个人资料图片 - Javascript - Login with Facebook, display user's profile picture after logged in successfully stackmob中当前登录的用户 - Current logged-in user in stackmob 一旦用户使用 React 和 Firebase 登录(从“登录”到“个人资料”),我如何更新我的导航栏? - How do I update my NavBar once a user is logged-in (from 'log in' to 'profile') using React & Firebase? 如何使用 FB.login() 获取 facebook 的用户信息 - How to get facebook's user's information with FB.login() 如果用户未登录 Firebase,如何重定向 - How to redirect if User Is NOT logged-in in Firebase 如何在 react-redux 中的 axios.get 方法中传递登录用户的 ID? - How can I pass the ID of logged-in user in the axios.get method in react-redux? 如何获取 Chrome 登录用户信息 - How to get Chrome Logged in User information
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM