Facebook授权&;登录

Facebook授权&;登录,facebook,authentication,login,Facebook,Authentication,Login,基本上,我对使用facebook api是新手,我在尝试让代码正常工作时遇到了问题,如果用户没有登录,下面的代码应该会提供提示,但我不确定这是怎么回事。 你好 window.fbAsyninit=函数(){ FB.init({ appId:'490455294310717',//应用程序仪表板中的应用程序ID channelUrl:'channel.php', status:true,//在初始化时检查登录状态? cookie:true,//设置会话cookie以允许服务器 xfbml:tr

基本上,我对使用facebook api是新手,我在尝试让代码正常工作时遇到了问题,如果用户没有登录,下面的代码应该会提供提示,但我不确定这是怎么回事。


你好

window.fbAsyninit=函数(){ FB.init({ appId:'490455294310717',//应用程序仪表板中的应用程序ID channelUrl:'channel.php', status:true,//在初始化时检查登录状态? cookie:true,//设置会话cookie以允许服务器 xfbml:true//是否解析此页面上的xfbml标记? }); //附加的初始化代码(如添加事件侦听器)如下所示 FB.getLoginStatus(函数(响应){ 如果(response.status===“已连接”){ var uid=response.authResponse.userID; accessToken=response.authResponse.accessToken; }else if(response.status===“未授权”){ FB.login(); }否则{ window.top.location文件https://www.facebook.com/index.php'; } }); }; //异步加载SDK的源代码 (功能(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”+(debug?/debug):“)+”.js”; ref.parentNode.insertBefore(js,ref); }(文档,/*debug*/false));
正如@CBroe在其中一条评论中提到的那样,
FB.login
由于弹出窗口拦截器,无法在用户交互之外调用


相反,提供一个按钮/链接,并调用此调用
FB.login

运行此操作时是否出现javascript错误?输出是什么?你试过在脚本标签上方移动吗?弹出窗口拦截器?建议仅在显式用户交互时调用FB.login–您仅在加载页面时调用它。
    <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"
          xmlns:fb="https://www.facebook.com/2008/fbml"> 
    <head>
      <title></title>
    </head>
    <body>
    <p>hello</p>
    <script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({
          appId      : '490455294310717', // App ID from the App Dashboard
          channelUrl: 'channel.php',
          status     : true, // check the login status upon init?
          cookie     : true, // set sessions cookies to allow your server to 
          xfbml      : true  // parse XFBML tags on this page?
        });

        // Additional initialization code such as adding Event Listeners goes here

        FB.getLoginStatus(function(response) {
            if (response.status === 'connected') {
                var uid = response.authResponse.userID;
                accessToken = response.authResponse.accessToken;
            } else if (response.status === 'not_authorized'){

                FB.login();

                } else {
                    window.top.location = 'https://www.facebook.com/index.php';
                }
        });

      };

      // Load the SDK's source Asynchronously
      (function(d, debug){
         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" + (debug ? "/debug" : "") + ".js";
         ref.parentNode.insertBefore(js, ref);
       }(document, /*debug*/ false));
    </script>

    <div id="fb-root"></div>

    </body>

</html

>