-1

最近我决定尝试使用javascript sdk集成facebook api connect ..经过一些尝试后我注意到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>
4

1 回答 1

0

为什么?

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

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

于 2012-08-29T22:53:52.317 回答