我正在拼命尝试在用户开始新的 Facebook session 之前强制注销。但在成功调用注销之前,auth.login 似乎登录了用户,并且我重定向了它们。所以这似乎是一个竞争条件,但我不知道如何绕过它。
FB.init({appId: xxxx, status: true, cookie: true, xfbml: true});
//Try to log out user
FB.logout();
//Show the FB div
if(FB) {
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
FB.getLoginStatus(function(response) {
if (response.session) {
login(response);
}
});
FB.Event.subscribe('auth.login', function(response) {
login(response);
//login redirects the user. Before logout fires()
});
} // end if(FB).
最佳答案
可能是这样的:
//initial login check
FB.getLoginStatus(function(response) {
if (response.session) {
//logged in, force logout
FB.logout(function() {
//logged out, subscribe to events
loginEvents();
});
} else {
//not logged in
loginEvents();
}
});
function loginEvents() {
FB.Event.subscribe('auth.logout', function(response) {
// do something with response
logout();
});
FB.Event.subscribe('auth.login', function(response) {
login(response);
//login redirects the user. Before logout fires()
});
}
关于javascript - 使用 FB.logout 避免 Facebook JavaScript API 中的竞争条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3836396/