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”} –