开发者

How can I get a notification when the user logs out from facebook.com?

The user is logged in to my site using the latest PHP SDK. If the user clicks the facebook logout URL that appears in my site, he logs out from facebook and is redirected back to my site where I can do some cleanups.

However, if while in session (in my site and in facebook) the user goes to www.facebook.com and logs out from there, my site is clueless a开发者_如何学运维bout it. I need to be notified about this in my site so I can do cleanups.

The only solution I can think of is to call from every page in my site to getLoginStatusUrl(), but this seems to be an overkill. Isn't there a way to ask facebook to call some URL in my site when the user logs out from facebook itself?


You can use js to subscribe to the auth.logout event as per the facebook example:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId: '<?php echo $facebook->getAppID() ?>',
      cookie: true,
      xfbml: true,
      oauth: true
    });
    FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
    FB.Event.subscribe('auth.logout', function(response) {
      window.location.reload();
    });
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜