在asp.net mvc應用程序中,我做了如下。
<a href="javascript:void(0);" class="logOff">Log out</a>
$(function() {
$(".logOff").click(function() {
//check if logout is
FB.getLoginStatus(function (response) {
console.log('inside login status');
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
FB.logout(function (response) {
FB.Auth.setAuthResponse(null, 'unknown');
});
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
console.log('response status not logged in');
}
});
window.location.href = '@Url.Action("LogOff", "Account")';
});
在調用註銷並刷新頁面之前,如果您在Facebook上繼續使用,您仍然連接? 如果您連續兩次調用註銷,它是相同的響應? (如果不是這不僅僅是通話和響應之間的時間問題) (並且,即使它沒有回答「爲什麼」部分,你不能通過重新加載響應中的頁面來解決這個問題嗎?) 哦和最後一個,「未定義」是另一個console.log我想? – 2012-01-13 10:58:27
@Flow'S,是'undefined'是一個不相關的控制檯日誌。 FB.logout()會將用戶從Facebook中註銷,但當前頁面FB對象直到刷新後纔會實現。我強烈希望在用戶註銷後不必手動刷新頁面。此外,我試圖刪除fbsr_ cookie,看看這是否刪除它 - 沒有效果。這以前工作,只是最近才改變。另外,我在使用FB JS SDK的hulu.com上嘗試了相同的測試,結果相同。這可能是SDK中的錯誤? – 2012-01-13 19:12:21
我目前使用'FB.logout'回調中的'FB.getLoginStatus'來確保JS-SDK忘記用戶。 – 2012-01-13 19:58:10