chrome中的Facebook JavaScript SDK Connect问题


Facebook JavaScript SDK Connect Issue in chrome

最近我决定尝试使用javascript sdk集成facebookapi连接。。经过一番尝试,我注意到chrome有问题。。可能我是唯一一个犯这种错误的人。。

:当我连接到facebook时,它会一次又一次地刷新。。不停,我必须关闭那个标签…不知道这可能会发生什么

我登录了Mozilla,它运行良好。。在那之后,我在chrome上再试了一次,但它仍然有同样的问题。。如果你对此有所了解,请写在评论上。

后端

    <?php if(!defined('DOCROOT')) exit('No directory browsing allowed!');
class fb_connect extends Frontend{
    private $allow_post = true;
    private $allow_get = true;
    function __construct(){
        parent::__construct();
    }
    function index(){
        $facebook = new Facebook(array(
          'appId'  => FBAPPID,
          'secret' => FBSECRETID,
        ));
        $user = $facebook->getUser();
        $outx = NULL;
        if ($user) {
            try {
                $user_profile = $facebook->api('/me');
                $output['user_profile'] =  $user_profile;
            } catch (FacebookApiException $e) {
                $user = null;
            }
        }
        $output['user'] =  $user;
        $this->tpl->contents['fb'] = $this->tpl->fetch('contents/fb_connect',$output);
        $this->tpl->meta['title'] = "Facebook Connect Test";
        //$this->tpl->meta['description'] = $this->lang['contact_meta_description'];
        //$this->tpl->meta['keywords'] = $this->lang['contact_meta_keywords'];
        $this->tpl->render('layouts/default');
    }
}
?>

**正面**

   <?php if ($user) : ?>
      Your user profile is
      <pre>
        <?php print htmlspecialchars(print_r($user_profile, true)) ?>
      </pre>
      <a  onclick="FB.logout();">Logout</a> 
    <?php else : ?>
      <fb:login-button></fb:login-button>
    <?php endif; ?>

    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo FBAPPID; ?>',
          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);
      }());
    </script>

为什么?

FB.Event.subscribe('auth.login', function(response) {
  window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
  window.location.reload();
});

FB.Event.subscribe(Event,函数(…){…})将在每次触发Event时触发。这是你的无限循环。该块中的console.log()只会触发一次,但由于您重新加载了整个页面,该事件将再次触发。