我确定我只是忽略了Facebook API文档中的内容 . 基本上,在我加载FB Graph之后,我需要知道会话是否处于活动状态...我不能简单地假设它们已经注销并且只是在'auth.statusChange'登录后才会重新渲染事件被触发 . 我需要马上知道 .
下面是我使用过的代码 . 最重要的是FB.getLoginStatus / getAuthResponse / getAccessToken不能像我期望的那样工作;基本上它在调用时指示它们是否已登录或退出 .
(function(d) {
// Create fb-root
var fb_root = document.createElement('div');
fb_root.id = "fb-root";
document.getElementsByTagName('body')[0].appendChild( fb_root );
// Load FB Async
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);
// App config-data
var config = {
appId : XXXX,
cookie: true,
status: true,
frictionlessRequests: true
};
window.fbAsyncInit = function() {
// This won't work.
// I can't assume they're logged out and rely on this to tell me they're logged in.
FB.Event.subscribe('auth.statusChange', function(response) {});
// Init
FB.init(config);
// These do not inidicate if the user is logged out :(
FB.getLoginStatus(function(response) { });
FB.getAuthResponse(function(response) { });
FB.getAccessToken(function(response) { });
};
}(document));
任何帮助深表感谢 . :)
1 回答
谢谢你的帮助,但我在另一篇文章中找到了答案:https://stackoverflow.com/a/7765144/560686
显然,当你仍然处于沙盒模式时
FB.getLoginStatus()
只有在他们're logged in, but not when they'注销后才会触发回调 . 为了实现这一点,我不得不禁用沙盒模式 . :)