js-api首次登录后没有扩展权限

js api no extended permissions after initial login

本文关键字:扩展 权限 登录 js-api      更新时间:2023-09-26

我正在尝试在我的应用程序中设置请求用户电子邮件的权限。

<script>
window.fbAsyncInit = function() {
  FB.init({
    appId      : 'APP_ID',
    status     : true, 
    cookie     : true,
    xfbml      : true,
    oauth      : true,
  });
  FB.Event.subscribe('auth.login', function(response) {
    //window.location.reload();
    window.location = "/welcome.html";
  });
};

(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));
</script>
<div id="fb-root"></div>
<div class="fb-login-button" data-scope="email" >
    Login with Facebook
</div>

当用户当前登录到facebook时,他们会看到一个对话框,要求他们允许我的应用程序。它还要求获得使用他们电子邮件的许可。这是预期的行为,并且有效。

当用户当前没有登录到facebook时,他们会看到一个登录对话框(这也是意料之中的事,而且有效),下一个出现的对话框是允许我的应用程序的对话框,但它没有访问他们电子邮件的权限,这就是我遇到麻烦的地方。

我已经阅读并尝试了其他问题中描述的各种方法。就像用onclick调用FB.login方法并以这种方式设置权限范围,但仍然没有成功。

FB.login(function(response) {
   if (response.authResponse) {
     window.location = "/welcome.html";  
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 }, {scope: 'email'});

我知道这是可能的,因为我已经看到其他几个应用程序正确地做到了这一点,我只是看不出我缺少了什么。我也尝试过xfbml方法,但遇到了与div相同的问题。

订阅该auth.login事件时要小心。当SDK在FB.init()中看到status : true时,它甚至在执行登录检查时被调用。

请注意我在这里使用它的操作:http://jsfiddle.net/dmcs/R4g47/(它被注释掉了,但你取消注释并运行脚本。你可以看到你想注意发送到它的状态。

FB.Event.subscribe('auth.login', function(response) {
    // {
    //   status: "",         /* Current status of the session */
    //   authResponse: {          /* Information about the current session */
    //      userID: ""          /* String representing the current user's ID */
    //      signedRequest: "",  /* String with the current signedRequest */
    //      expiresIn: "",      /* UNIX time when the session expires */
    //      accessToken: "",    /* Access token of the user */
    //   }
    // }
    alert('event status: ' + response.status);
});