通过Facebook登录获取登录用户个人资料信息 [英] Get logged-in user profile information with Facebook Login

查看:1253
本文介绍了通过Facebook登录获取登录用户个人资料信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上集成了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, 链接: https://www.facebook.com/xxxxx, 现场: XXX, 名: XXXX, 时区:XX, updated_time:XXXXX , 验证:真正}! 

可以获取用户的年龄和生日,以验证用户是否为18岁以上?如果是,我该怎么做?

解决方案

在请求许可之前,请使用任何可用的公开个人资料信息。例如,任何安装您的应用程序的人都会在公开个人资料中包含一个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 +。

  / *使API调用v.2.3 * / 
FB.api(
/ me?fields = age_range,
function(response){
if(response&&!response.error){
/ *处理结果* /
}
}
);

这应该返回如下:

  {
age_range:{
min:21
},
id:< user_id&
}

FIELDS




  • max (unsigned int32)此人的年龄范围的上限。枚举{17,20或空}。


  • min (unsigned int32)此人的年龄范围的下限。枚举{13,18,21}
    默认




年龄范围字段文档这里 https://developers.facebook.com/docs/graph-api/reference/age-range /



如何在这里使用字段docs https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3#fields


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?

解决方案

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

这篇关于通过Facebook登录获取登录用户个人资料信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆