自动登录Facebook的 - FB.Event.subscribe auth.login不起作用 [英] Auto login facebook - FB.Event.subscribe auth.login doesn't work

查看:277
本文介绍了自动登录Facebook的 - FB.Event.subscribe auth.login不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我今天的code为自动登录的会员存在爆发。
通常这code完美的作品,与萤火虫的支票,我看到有发现由于某些原因'auth.login')问题,并为此呼吁window.location.reload(后;不工作。 (如果我手动刷新则该成员显示为连接正常,需要一个页面刷新的问题就是自动登录前的会话是打开的)
我也想看看问题是否只是auto.login'和'auth.authResponseChange取代了它,当我做在页面上保持清爽......所以我想这个问题是auth.login触发。
没有任何人知道的,可能会导致这一问题的特殊原因或所做的任何变更的Facebook?

* 更新的* BUG就解决了!此问题已修复被Facebook。

这个bug报告,也被Facebook在这里找到答案 -

https://developers.facebook.com/bugs/524245490930206?browse=search_50f87d9e8869a5e06191882#

顺便说一句,这是一个工作AGAIN code:

 < D​​IV ID =FB-根>< / DIV>
    <脚本>
      window.fbAsyncInit =功能(){
        FB.init({
              APPID:'?< PHP = $ APP_ID>,
              状态:真正的,//检查登录状态
              饼干:真,//启用cookies来允许服务器访问会话
              XFBML:真,//解析XFBML
              OAuth的:真
        });      //附加的初始化code在这里
        FB.Event.subscribe('auth.login',函数(响应){
          window.location.reload();
        });
      };
      //异步加载SDK
      (函数(D){
         VAR JS,ID ='Facebook的jssdk',REF = d.getElementsByTagName('脚本')[0];
         如果(d.getElementById(ID)){回报;}
         JS = d.createElement('脚本'); js.id = ID; js.async = TRUE;
         js.src =//connect.facebook.net/en_US/all.js#xfbml=1;
         ref.parentNode.insertBefore(JS,REF);
       }(文件));
    < / SCRIPT>


解决方案

看来我遇到了同样的问题。

直到几个小时前,当一个用户(谁已经授权并登录到我的应用程序previously)打开我的网站和饼干届满,登录按钮出现,但几秒钟(时间为后JS的SDK触发登录功能),他是自动登录的和页面而不登录按钮和用户信息被重新加载。

现在,当一个已经注册的用户打开我的网站的cookie到期后,登录按钮再次出现,但用户不会自动登录和页面不会重新加载像以前那样。奇怪的是,如果我上的登录按钮,单击它也不起作用!如果我现在刷新页面手动登录按钮消失,并显示用户信息,如此看来,用户实际上是登录的,但没有抓住事件触发页面重载。

如果我手动再次注销和登录(因此使用PHP SDK)一切正常。

我的code:

 <脚本>
        window.fbAsyncInit =功能(){
            FB.init({
                APPID:'< PHP的echo $ facebook-> getAppID()>,
                饼干:真实,
                XFBML:真实,
                OAuth的:真
            });
            FB.Event.subscribe('auth.login',函数(响应){
                window.location.reload();
            });
            FB.Event.subscribe('auth.logout',函数(响应){
                window.location.reload();
                });
        };
        (函数(){
            变种E =使用document.createElement('脚本'); e.async = TRUE;
            e.src = document.location.protocol +
                //connect.facebook.net/en_US/all.js';
                的document.getElementById('FB-根')的appendChild(E)。
        }());
        功能facebookLogin(){
            FB.login(功能(响应){
                //处理响应
            },{范围:电子邮件,publish_stream,read_friendlists'});
        }
    < / SCRIPT>

更新我说这几行对我的js code:

  FB.Event.subscribe('auth.statusChange',函数(响应){
                警报('会话的状态是:'+ response.status);
            });

当用户打开后,我的网页所以现在令牌过期:


  • 的PHP SDK检测他尚未登录,并显示登录对话框
    (像以前一样)

  • 的JavaScript SDK触发登录功能(如
    前)

  • 用户得到定期登录(像之前)(我可以知道
    这是肯定的,因为现在它弹出警报:的状态
    会话:连接)

  • 但..事件auth.login不会触发 - >
    脚本不知道成功登陆 - >页面不
    重载

for some reason today my code for auto login for existed members broke. normally this code works perfect, after a check with firebug I saw that there is a problem finding 'auth.login' for some reason, and therefor the call for window.location.reload(); isn't working. (if I refresh manually then the member shows as connect properly,the problem is just the auto login before the session is open that need a page refresh) I also tried to see if the problem is only 'auto.login' and replaced it with 'auth.authResponseChange' when I did it the page kept on refreshing ... so I figure that problem is with 'auth.login' trigger. does anyone knows for a special reason or any change facebook made that could cause this problem?

*update* BUG is solved! this problem was fixed by facebook.

this bug was reported and also answered by facebook here-

https://developers.facebook.com/bugs/524245490930206?browse=search_50f87d9e8869a5e06191882#

BTW,Here is A WORKING AGAIN code:

<div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
              appId  : '<?php =$APP_ID ?>',
              status : true, // check login status
              cookie : true, // enable cookies to allow the server to access the session
              xfbml  : true,  // parse XFBML
              oauth  : true
        });

      // Additional initialization code here
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
      };
      // 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#xfbml=1";
         ref.parentNode.insertBefore(js, ref);
       }(document));
    </script>

解决方案

it seems i'm experiencing the same problem ..

Till a few hours ago, when a user (who had already authorized and logged in to my app previously) opened my website and the cookie was expired, the login button appeared but after a few seconds (the time for the JS SDK to trigger the login function), he was automatically logged-in and the page was reloaded without the login button and with the user information.

Now when an already registered user opens my site after cookie expired, the login button appears again, but the user isn't automatically logged in and the page doesn't reload like it did before. The strange thing is that if i click on the login button it doesn't work either! If i now refresh the page manually the login button disappears and user information is displayed, so it seems that the user was actually logged-in but the event was not caught to trigger the page reload.

If i manually log-out and login again (thus using the php sdk) everything works.

My code:

<script>
        window.fbAsyncInit = function() {
            FB.init({
                appId: '<?php echo $facebook->getAppID() ?>',
                cookie: true,
                xfbml: true,
                oauth: true
            });
            FB.Event.subscribe('auth.login', function(response) {
                window.location.reload();
            });
            FB.Event.subscribe('auth.logout', function(response) {
                window.location.reload();
                });
        };
        (function() {
            var e = document.createElement('script'); e.async = true;
            e.src = document.location.protocol +
                '//connect.facebook.net/en_US/all.js';
                document.getElementById('fb-root').appendChild(e);
        }());
        function facebookLogin() {
            FB.login(function(response) {
                // handle the response
            }, {scope: 'email, publish_stream, read_friendlists'});
        }
    </script>

UPDATE I added this few lines to my js code:

FB.Event.subscribe('auth.statusChange', function(response) {
                alert('The status of the session is: ' + response.status);
            });

So now when the users opens my page after token expired:

  • the php sdk detects he's not logged in and displays the login dialog (like before)
  • the javascript sdk triggers the login functions (like before)
  • the user gets regularly logged (in like before) (i can know it for sure now because it pops up the alert: The status of the session is:connected)
  • BUT.. the event auth.login is not triggered -> the script isn't aware of succeeded log in -> the page is not reloaded

这篇关于自动登录Facebook的 - FB.Event.subscribe auth.login不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆