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

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

问题描述

由于某种原因,今天我的现有成员自动登录代码坏了.通常这段代码可以完美运行,在检查 firebug 后,我发现由于某种原因在查找 'auth.login' 时出现问题,因此调用 window.location.reload();不工作.(如果我手动刷新然后成员显示为正确连接,问题只是在会话打开之前自动登录需要刷新页面)我还尝试查看问题是否只是auto.login",并在我执行此操作时将其替换为auth.authResponseChange",页面不断刷新……所以我认为问题出在auth.login"触发器上.有没有人知道出于特殊原因或 Facebook 所做的任何可能导致此问题的更改?

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?

*更新* BUG解决了!此问题已由 Facebook 修复.

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

此错误已被 facebook 报告并在此处回答-

this bug was reported and also answered by facebook here-

https://developers.facebook.com/bugs/52424549095e808e68e68f87d9e8869#

顺便说一句,这是一个重新工作的代码:

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 ..

直到几个小时前,当一个用户(之前已经授权并登录到我的应用程序)打开我的网站并且 cookie 已过期时,登录按钮出现但几秒钟后(JS SDK 的时间)触发登录功能),他自动登录,页面重新加载,没有登录按钮和用户信息.

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.

现在,当已经注册的用户在 cookie 过期后打开我的网站时,登录按钮再次出现,但用户不会自动登录,页面也不会像以前那样重新加载.奇怪的是,如果我点击登录按钮,它也不起作用!如果我现在手动刷新页面,登录按钮会消失并显示用户信息,因此似乎用户实际上已登录但未捕获到触发页面重新加载的事件.

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.

如果我手动注销并再次登录(因此使用 php sdk),一切正常.

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

我的代码:

<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 我在我的 js 代码中添加了这几行:

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:

  • php sdk 检测到他未登录并显示登录对话框(像以前一样)
  • javascript sdk 触发登录功能(如之前)
  • 用户定期登录(像以前一样)(我知道现在可以肯定,因为它会弹出警报:会话是:已连接)
  • 但是.. 事件 auth.login 没有被触发 ->脚本不知道成功登录 -> 页面不是重新加载

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

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