我正在开发一款游戏,要求用户登录,然后使用登录详细信息更新排行榜。但问题是,在用户登录后,登录对话框不会自动关闭,用户不会被重定向到游戏。以下是从here
中获取的代码window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
shepResponse = response;
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected')
testAPI();
}
else if (response.status === 'not_authorized') {
FB.login();
} else {
FB.login();
}
});
};
(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 = "http://connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
}
答案 0 :(得分:0)
尽量不要在fbAsyncInit函数中包装FB.Event.subscribe和testAPI()。
也可以尝试auth.statusChange而不是auth.authResponseChange
var fb_handleStatusChange = function(response){
if(response.authResponse){
//用户登录
} else {
//未登录或退出
}
}
FB.Event.subscribe('auth.statusChange',fb_handleStatusChange);
另外,我认为登录重定向应该是一个包含此代码并正在侦听状态更改的页面。我不会重定向回到用于登录的页面。