【问题标题】:Facebook JS api: Not receiving user email despite asking for permissionsFacebook JS api:尽管请求权限但未收到用户电子邮件
【发布时间】:2013-06-19 10:48:23
【问题描述】:

对于我的 facebook 画布应用程序,我一直在尝试访问用户的电子邮件。即使我要求它,它仍然没有出现(生日,这也是一个额外的许可,确实出现了)。 (在 addscope 函数中)

<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
  FB.init({
    appId      : '--------------', // App ID
    channelUrl : 'http://www.---------.com/channel.html', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });


    FB.Event.subscribe('auth.statusChange', function(response) {
        if(response.status === 'connected')
            {
                console.log('Hello there!');
                addScope();

            }
        else if(response.status === 'not_authorized')
            {
               console.log('not authorized');
                addScope();

            }
        else
            { 
                console.log('not logged in');
                addScope();
            }
    });



  FB.Event.subscribe('auth.authResponseChange', function(response) {
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') {
      // ...
    } else if (response.status === 'not_authorized') {
      // ...

    } else {
      //...
    }
  });
  };

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


  function addScope()
  {
      FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('In addscope function, ' + response.email + response.birthday);
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 },{scope: 'email,user_birthday'});

  }
</script>

</body>
</html>

【问题讨论】:

    标签: javascript facebook api permissions


    【解决方案1】:

    查看是否通过代码设置了正确权限的一种有效方法是使用以下代码(在查询部分更改您要检查的字段):

    FB.api({ method: 'fql.query', query: 'SELECT user_status,friends_status,user_photos,friends_photos,user_location,friends_location FROM permissions WHERE uid=me()' }, function(resp) {   
    for(var key in resp[0]) {   
        if(resp[0][key] === "1")   
            console.log(key+' is granted');   
        else   
            console.log(key+' is not granted');   
    }   
    });
    

    用户可能没有授予访问电子邮件 ID 的权限。

    【讨论】:

      【解决方案2】:

      删除这个:

      FB.Event.subscribe('auth.authResponseChange', function(response) {
      // Here we specify what we do with the response anytime this event occurs. 
      if (response.status === 'connected') {
        // ...
      } else if (response.status === 'not_authorized') {
        // ...
      
      } else {
        //...
      }
      });
      };
      

      再试一次

      【讨论】:

        【解决方案3】:

        据我所知,如果没有在其他地方抛出错误并且正在调用“addScope”方法,那么您的代码是正确的。只需确保确实有一个值要返回(用户有生日和电子邮件,否则您将无法取回。如此处所述:https://developers.facebook.com/docs/reference/api/user/

        我正在使用 FB api,并且在使用用户访问令牌时获取电子邮件和其他字段没有问题。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2013-03-07
          • 1970-01-01
          • 1970-01-01
          • 2023-03-17
          • 1970-01-01
          • 1970-01-01
          • 2014-07-23
          相关资源
          最近更新 更多