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

妖精的绣舞 提交于 2019-11-30 12:58:24

问题


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...


回答1:


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.




回答2:


try this:

function fbLogoutUser() {
FB.getLoginStatus(function(response) {
    if (response && response.status === 'connected') {

        FB.logout(function(response) {
            document.location.reload();
        });
    } else if (response.status === 'not_authorized') 
        {
             FB.logout(function(response) {
            document.location.reload();
            });
        }
});}


来源:https://stackoverflow.com/questions/19842610/fb-logout-called-without-an-access-token-javascript-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!