2013-06-22 94 views
0

我正在嘗試使用Facebook API來查看用戶是否從我的網站登錄。看用戶是否登錄到facebook

當我調用FB.getLoginStatus時,我沒有得到任何迴應。我嘗試了我看到的每個示例代碼以獲得響應,但什麼也沒得到。可能有人請幫我找出這個問題與我的代碼:

<div id="fb-root"></div> 
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"> 
<script type="text/javascript"> 
     window.fbAsyncInit = function() { 
      FB.init({ 
      appId  : 'my_app_id', // App ID 
      status  : true, // check login status 
      cookie  : true, // enable cookies to allow the server to access the session 
      xfbml  : true // parse XFBML 
      }); 
     }; 

     // Load the SDK Asynchronously 
     (function(d){ 
      var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      d.getElementsByTagName('head')[0].appendChild(js); 
     }(document)); 
    function GetFBLoginStatus() { 
    debugger; 
    window.fbAsyncInit() 
      alert("get status"); 
    FB.getLoginStatus(function(response) { 
     alert("inside call back function"); 
     if (response.status === 'connected') { 
     alert("logged in"); 
     } else if (response.status === 'not_authorized') { 
      alert("not authorized"); 
     } else { 
      alert("logged out"); 
     } 
     return true; 
    }, true) 
} 
</script> 

回答

0

沒有爲你的第一個腳本沒有結束標籤:

<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"> 

應該

<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"></script> 

現在的瀏覽器認爲第二個腳本標記是在第一個腳本標記中定義的腳本的一部分。你得到解析錯誤,其餘的不執行。

+0

感謝,固定的,但仍是FB.getLoginStatus不執行被定義爲參數的函數: FB.getLoginStatus(功能(響應){ 警報(「內部回叫函數」); (response.status ==='not_authorized'){ alert(「not authorized」); } if(response.status ==='connected'){ alert(「logged in」); }其他{ 警報(「註銷」); } – user2512231

相關問題