2012-09-30 98 views
0

我已經實現了基於Facebook的登錄。 FB.login完美地工作,但FB.logout沒有。我嘗試過使用不同的FB.init,刪除cookies,連續多次運行註銷頁面,但登錄我的用戶的唯一方法是在Facebook本身。FB.logout不會註銷

我使用註銷的代碼是:

<div id="fb-root"></div> 
<script src="http://connect.facebook.net/en_US/all.js"></script> 
<script> 

    FB.init({ 
    appId: '***************', 
    xfbml: true, 
    status: true, 
    cookie: true 
    }); 

    FB.getLoginStatus(); 

    FB.logout(); 
</script> 

任何想法? 謝謝

+1

您還需要在php中銷燬會話,它可以通過'session_destroy();' –

+0

謝謝。你知道asp等價物嗎? –

+0

試過session_destroy()和session_unset(),但仍然不起作用:( –

回答

0

你有沒有試過有一些按鈕onclick事件是FB.logout();

function logout(){ 
    FB.logout(function(response) { 
     // user is now logged out 
    }); 
} 

    <button onclick="logout()">LogOut</button> 

嘗試這個

+0

感謝您的幫助,它真的起作用了! 我確信我需要FB.init才能運行FB.logout,顯然不是。 –

0

嘗試這樣做:

<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : 'YOUR_APP_ID', // App ID 
     channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     xfbml  : true // parse XFBML 
    }); 

    // Additional initialization code here 
    }; 

    // Load the SDK Asynchronously 
    (function(d){ 
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement('script'); js.id = id; js.async = true; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    ref.parentNode.insertBefore(js, ref); 
    }(document)); 
</script> 

,然後調用FB.logout()。 FB必須在初始化之前。

從文檔:

此代碼加載SDK異步所以它不會阻止加載網頁的其他元素。這對確保用戶和SEO機器人的快速頁面加載特別重要。

上述代碼中的URL是相對協議。這使得瀏覽器可以通過與包含頁面相同的協議(HTTP或HTTPS)加載SDK,從而防止「不安全內容」警告。

加載SDK後立即運行分配給window.fbAsyncInit的函數。任何你想在SDK加載後運行的代碼都應該放在這個函數中,並且在調用FB.init之後。例如,您可以在這裏測試用戶的登錄狀態或訂閱您的應用程序感興趣的任何Facebook事件。