2011-04-30 36 views
0

在我的一個應用程序中,我使用客戶端Facebook javascript api來跟蹤用戶的Facebook登錄狀態。FB.getSession()返回null

我已經有用戶已經與facebook應用程序連接,並且用戶登錄到了facebook。

現在,當我打電話FB.getSession()返回null,在調用FB.getLoginStatus()也沒有給我response.session ....

此行爲是在不同的瀏覽器不同,它的工作原理罰款鉻,但不是在Firefox 4.我在Firefox中清除cookie仍然沒有按預期工作。

這是客戶端api信任還是我應該選擇服務器端API?

代碼:

window.fbAsyncInit = function() { 
    FB.init({ 
     appId: '0000000000', 
     status: true, 
     cookie: true, 
     xfbml: true 
    }); 

    FB.getLoginStatus(function(response) { 
     if (response.session) { 
     // This block should have been called. 
     alert('logged in') 
     } else { 
     // no user session available, someone you dont know 
     alert('not logged in') 
     } 
    }, true); 


    var session = FB.getSession(); //Must not return null... 

}; 

任何想法?

+0

如何與我們分享一些代碼? – ifaour 2011-04-30 20:33:27

回答

0

它使用非異步接近後工作。

代碼

<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 
FB.init({ 
    appId : '00000000000', 
    status : true, // check login status 
    cookie : true, // enable cookies to allow the server to access the session 
    xfbml : true // parse XFBML 
}); 


$(function(){ 
    //var session = FB.getSession(); 

    alert(FB.getSession()); 
}) 

</script> 

不知道,雖然你爲什麼不將其與異步的方式工作。

0

這僅僅是因爲FB.getSession()沒有初始化。

您無法將事件添加到FB.getLoginStatus中,該功能在Facebook初始化時觸發FB.getSession()功能,從而使用異步方法。