3
我一直在試圖讓我的網站檢查用戶是否在頁面加載中登錄,但是我仍然無法使其工作,儘管遵循以下API說明,這裏是一個例子:Facebook API:檢查用戶是否已登錄連接
<!DOCTYPE html>
<html>
<head>
<title>My Facebook Login Page</title>
</head>
<body>
<div id="fb-root"></div>
<script>
alert('hello');
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID',
status : true,
cookie : true,
xfbml : true,
oauth : true
});
FB.getLoginStatus(function(response) {
console.log(response);
alert('hello2');
});
FB.Event.subscribe('auth.statusChange', function(response) {
alert('hello2');
});
FB.Event.unsubscribe('auth.statusChange');
};
(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));
</script>
</body>
</html>
警報永遠不會連打,除非用戶登錄,如果他被註銷,此警報或任何將是代碼塊永遠不會觸發內。
有時auth.statusChange事件不會觸發,我認爲這是由於網絡延遲或服務器超時。我發現與FB一起工作需要靈活處理頁面加載,而不是100%的時間「運行」。刷新可能會正確觸發事件。 –
好吧,我剛剛意識到,它只適用於如果用戶登錄到Facebook(與應用程序authed或W/O應用程序authed) 有無論如何檢查用戶是否註銷或註銷用戶的狀態?我覺得getLoginStatus應該檢查用戶是否註銷,但不是,只有當他們授權了應用程序。 我採納了你對getLoginStatus的建議,但它似乎仍然不起作用。 – Ven
嗯..你的迴應應該返回一個像這樣的對象:{authResponse:null, status:「unknown」} –