2011-11-15 39 views
-1

我正在使用下面的代碼,但它始終表示未登錄(即使我已登錄 狀態)。我該如何解決這個問題?用於Facebook的JavaScript SDK未獲取登錄狀態

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
    FB.init({appId:"my appid", 
      status: true, 
      cookie: true, 
      logging:false, 
      xfbml: true, 
      oauth:true}); 

    FB.getLoginStatus(function(response) { 
     alert ("here11"); 
     if (response.session) { 
      alert ("already logged in"); 
     } 
     else { 
      alert ("not logged in"); 
     } 
    }); 
</script> 

回答

1

您是如何登錄的?我懷疑你要facebook.com登錄,然後期待這說你已經登錄?這不起作用。您必須使用API在您自己的域上啓動會話。試試這個:

FB.login(function(response) { 
    if (response.authResponse) { 
     console.log('Welcome! Fetching your information.... '); 
     FB.api('/me', function(response) { 
      console.log('Good to see you, ' + response.name + '.'); 
      FB.logout(function(response) { 
       console.log('Logged out.'); 
      }); 
     }); 
    } 
    else { 
     console.log('User cancelled login or did not fully authorize.'); 
    } 
}, {scope: 'email'}); 

而且,檢查the documentation

+0

我的目標是得到用戶是否喜歡頁面或沒有權限提示 如果我使用FB.login,它總是詢問權限,我們如何避免權限promt使用javascript SDK –

+0

您需要權限爲了獲得關於某人的任何信息。就像他們的臉書ID和他們的喜歡。沒有至少基本的權限,沒有辦法做到這一點。 – Abby