2012-08-29 48 views
-1

最近我決定嘗試整合Facebook的API使用JavaScript SDK連接。經過一些嘗試我注意到的問題與鍍鉻..可能是我得到這種類型的錯誤的唯一的人..Facebook上的JavaScript SDK連接問題

:當我連接到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> 
+0

聽起來像是你有一個無限循環。發佈您的代碼。 –

+0

@保羅添加我使用的代碼.. –

回答

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,功能(...){...})將觸發每事件的點火時間。有你的無限循環。一個執行console.log()在該塊只能觸發一次,但因爲你重新加載整個頁面,該事件將再次觸發。