我有以下代码,它工作了一段时间,过了一段时间我无法再触发authResponseChange事件。我删除了所有的cookie,取消了应用程序并重新添加了它。我该如何处理这个事件?
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.authResponseChange', handleResponseChange);
};
function handleResponseChange(response) {
document.body.className = response.authResponse ? 'connected' : 'not_connected';
if (response.authResponse) {
console.log(response);
alert('connect');
}
}
</script>
答案 0 :(得分:1)
这必须解决你的问题
https://stackoverflow.com/questions/8212668/facebook-javascript-events-not-fired-any-way-i-turn-it
var connected;
FB.init({
appId : 'XXX',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
oauth : true, // enables OAuth 2.0
channelUrl : 'http://XXX/channelUrl'
});
FB.getLoginStatus(handleUserStateChange);
FB.Event.subscribe('auth.authResponseChange', handleUserStateChange);
function handleUserStateChange(response) {
connected = !!response.authResponse;
}
setInterval(function() {
FB.getLoginStatus(handleUserStateChange, true);
}, 10000) // poll every 10 seconds
答案 1 :(得分:0)
我没有在代码中看到sdk加载。你确定要初始化吗?
(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";
ref.parentNode.insertBefore(js, ref);
}(document));