首页 文章

如果弹出窗口被阻止,fb.login弹出窗口不会显示其他请求的权限

提问于
浏览
3

我正在尝试使用Facebook建议的Javascript SDK在Facebook登录时请求其他权限 . 我使用scope参数将附加请求作为FB.login()的一部分 . 我的Chrome浏览器阻止了弹出窗口 . 当我将包含FB.login和范围参数的页面加载到我的浏览器中时,Chrome会阻止自动弹出窗口 . 当我点击html按钮执行facebook登录和授权请求时,fb弹出窗口显示的唯一权限是基本信息 . 但是,如果我允许弹出窗口,那么当我加载页面时,会自动显示facebook授权弹出窗口,而无需单击按钮来启动fb登录 . 显示此自动弹出窗口时,它现在显示我在范围参数中包含的其他权限 . 当弹出窗口被阻止时,如何获得在fb登录弹出窗口中显示的其他权限?

以下是我的代码:

<!DOCTYPE html>
<html>
<head>

<div id="fb-root"></div>
<script>
  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'MY_APP_ID', // App ID
      channelUrl : '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
    });

    // Additional init code here
    FB.getLoginStatus(function(response) {
                if (response.status === 'connected') {
                        // connected
                } else if (response.status === 'not_authorized') {
                        // not_authorized
                                login();
                } else {
                        // not_logged_in
                                login();
                }
        });

  };
function login() {
        FB.login(
                function(response) {
                                if (response.authResponse) {
                                // connected
                                } else {
                                // cancelled
                                }
                },
                {scope: 'email, user_birthday'}
        );
}

  // 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));
</script>
</head>

<body>
<button type="button" onclick="FB.login()">login</button>
</body>
</html>

1 回答

  • 3

    FB.login 不能在事件处理程序(用户启动)之外使用,因为它在Canvas外部使用时会创建弹出窗口 . 而是显示一个用户可以单击以执行 FB.login 的按钮 .

    你的按钮没有要求权限的原因很简单,因为你没有在函数调用中添加任何东西 - 你使用 FB.login() - 没有烫发 .

相关问题