FaceBook FB.ui logout dont fire

908 Views Asked by At
FB.ui(
       {
         method: 'feed',
         name: 'some text',
         link: 'some text',
         picture: 'aa.jpg',
         caption: 'some text',
         description: 'some text',
         message: 'some text'
       },
       function(response) {
         if (response && response.post_id) {
            alert('Post was published.');               
        } else {
            alert('Post was not published.');
         }
       });
}

That code WORK fine, now i like after :

alert('Post was published.');

to be logged out from facebook, silently HOW ?

Adding that code After the alert('post publish') did not do anything !!

FB.ui(
 { method:'auth.logout',  display:'hidden' },
 function() { alert("you're logged out!"); }
);

i have found : FB auth.logout is being raised after being logged in using the "server-side-workflow" (OAuth 2.0) but not sure i understand the code enough to know it do what i ask !

1

There are 1 best solutions below

1
On BEST ANSWER
  1. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

  2. https://developers.facebook.com/docs/reference/javascript/FB.logout/

Best Practices

FB.logout will log the user out of both your site and Facebook. You will need to have a valid access token for the user in order to call the function.

Calling FB.logout will also invalidate the access token that you have for the user, unless you have the offline_access permission.

I wrote a sample using the comments box to fire the auto logout http://shawnsspace.com/fb.logout.test.php

THE CODE:


    <div id="fb-root"></div>    
    <script>
      window.fbAsyncInit = function() {
        FB.init({
    appId  : '112104298812138',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true, // parse XFBML
    //channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
    oauth  : true // enable OAuth 2.0
        });
FB.Canvas.EarlyFlush.addResource("http://shawnsspace.com/index.php");
FB.Canvas.setAutoResize();
            FB.getLoginStatus(function(response) {
              if (response.authResponse) {

                var accessToken = response.authResponse.accessToken;
              } else {
              }
            }); 
    FB.Event.subscribe('comment.create', function(response) {
     //alert(JSON.stringify(response));
        FB.logout(function(response) {
        window.location.reload();
        });
    });
        FB.Event.subscribe('auth.login', function(response) {
        //top.location.href = 'http://apps.facebook.com/shawnsspace/fbcomments.php?ref=loggedin';
        window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
        //top.location.href = "http://apps.facebook.com/shawnsspace/fbcomments.php?ref=loggedout";
        alert('logged out');
        });
      };
      (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>