2

我有以下代码,它可以工作一段时间,然后过一段时间我无法再触发 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>
4

2 回答 2

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
于 2013-04-10T15:25:01.940 回答
0

I don't see the sdk loading in your code. Are you sure you are initializing it?

(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));
于 2012-09-03T18:06:04.663 回答