Facebook API,无法获取名字和个人资料信息

时间:2016-03-21 18:52:27

标签: facebook

从一周开始,我们面临的问题是没有从Facebook获取用户个人资料信息可能是用户的设置,它正在阻止应用访问他们的个人资料信息(名字和姓氏)。只是想知道是否有人面对同样想知道什么设置会造成这个问题。

1)我尝试更改应用设置但需要配置文件信息,因此无法取消选中该选项

2)我已尝试将所有其他方式设置为隐私但无法反映

错误:控制台中没有错误。

并允许用户在没有Facebook信息信息的情况下登录。

如果有人遇到此错误,此问题的设置/解决方案是什么

设备:Web App和IOS

2 个答案:

答案 0 :(得分:0)

我已经知道问题出在哪里,问题来自IOS app。

https://developers.facebook.com/docs/facebook-login/permissions#reference-public_profile

这里明确提到公共资料信息:

在网络上,public_profile隐含在每个请求中,并不是必需的,尽管最佳做法是声明它。在iOS和Android上,您必须在登录流程中手动请求它。

因此,我们需要在IOS app中注册时明确调用获取信息。

答案 1 :(得分:0)

这是完整的示例,您只需要通过fields=first_name,last_name,email请求FB.api传递

<script>

 window.fbAsyncInit = function() {
  FB.init({
    appId      : 'YOUR_APP_ID', 
    status     : true, 
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });
 };

 (function(d){
  var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
  js = d.createElement('script'); js.id = id; js.async = true;
  js.src = "//connect.facebook.net/en_US/all.js";
  d.getElementsByTagName('head')[0].appendChild(js);
 }(document));

function facebookAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.login(function(response){
        if (response.authResponse && response.status === 'connected') 
        {
            FB.api('/me?fields=first_name,last_name,email', function(response) {
                console.log('Successful login for: ' + response.first_name+' '+response.last_name);
                console.log(response.first_name);
                console.log(response.last_name);
                console.log(response.email);
            });
        }
      },
      {
        scope: 'email',
        auth_type: 'rerequest'
     });
}
</script>

在你的html文件中只需调用函数facebookAPI()即可获取任何已登录的facebook用户的详细信息

<a href="javascript:void(0);"  onclick="facebookAPI();">CLICK TO FETCH FACEBOOK USER</a>