今天出于某种原因,我的现有成员(member)自动登录代码损坏了。 通常这段代码工作完美,在用 Firebug 检查后我发现由于某种原因在查找“auth.login”时出现问题,因此调用 window.location.reload();不工作。 (如果我手动刷新然后成员显示为正确连接,问题只是在 session 打开之前自动登录需要刷新页面) 我还尝试查看问题是否只是“auto.login”,并在我这样做时将其替换为“auth.authResponseChange”,页面一直在刷新......所以我认为问题出在“auth.login”触发器上。 有谁知道出于特殊原因或 facebook 所做的任何更改可能会导致此问题?
*更新* BUG解决!此问题已由 Facebook 修复。
此错误已报告并由 facebook 在这里回答-
https://developers.facebook.com/bugs/524245490930206?browse=search_50f87d9e8869a5e06191882#
顺便说一句,这是一个重新工作的代码:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?php =$APP_ID ?>',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true
});
// Additional initialization code here
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
};
// Load the SDK Asynchronously
(function(d){
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#xfbml=1";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
最佳答案
我把auth.login改成了auth.statusChange,还把所有的东西都包裹在了getLoginStatus里,所以它只在没有连接的时候运行,看起来工作正常。看起来像这样(在 window.fbAsyncInit = function() { 内)
FB.getLoginStatus(function(response) {
if (response.status != 'connected') {
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// whatever code runs when user logs in
}
});
}
});
关于javascript - 自动登录 facebook - FB.Event.subscribe auth.login 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14339899/