FB.logout() called without an access token. javascript sdk

Jared Eitnier picture Jared Eitnier · Nov 7, 2013 · Viewed 28.6k times · Source

Totally lost on this and docs don't really give any insight on this...

Using the Facebook Javascript SDK in my app with this login button code:

<fb:login-button scope="manage_pages,read_insights,ads_management" autologoutlink="true" size="large"></fb:login-button>

As per the docs, autologoutlink=true param turns the login button to log out once the user is logged in. I want to keep this functionality and not write my own button code

This event calls FB.logout but still returns the error message in the callback

FB.Event.subscribe('auth.logout', function(response) {                                              
    FB.logout(function(response) {
        // FB.logout() called without an access token.
    });
});

I would like to use the Facebook Login Widget and not my own button for login, so the other answers on the same subject don't help. I don't understand how I'm supposed to pass the access_token to prove I'm authorized to logout...

Answer

Jared Eitnier picture Jared Eitnier · Nov 7, 2013

Apparently this isn't possible, at least in no way I can figure out. Quick solution is call this function from a custom Log Out button:

function fbLogoutUser() {
    FB.getLoginStatus(function(response) {
        if (response && response.status === 'connected') {
            FB.logout(function(response) {
                document.location.reload();
            });
        }
    });
}

The page reload makes another request to Facebook which then sees the unauthorized state and removes the cookie from the browser which in turn invalidates the access_token. So this logs out the user from the site and from Facebook.