FB.logout() called without an access token

前端 未结 6 1806
谎友^
谎友^ 2020-11-29 03:10

I\'m trying to log out of a website i\'ve created with Facebook integrated. Logging in works fine, but when I want to log out Firebug consistently gives me this error:

6条回答
  •  [愿得一人]
    2020-11-29 04:10

    The error says that you don't have an access token, you have to check for one using the FB.getAccessToken() function.

    If there is no access token the function returns null. See example below:

       function facebooklogout() {
        try {
            if (FB.getAccessToken() != null) {
                FB.logout(function(response) {
                    // user is now logged out from facebook do your post request or just redirect
                    window.location.replace(href);
                });
            } else {
                // user is not logged in with facebook, maybe with something else
                window.location.replace(href);
            }
        } catch (err) {
            // any errors just logout
            window.location.replace(href);
        }
       }
    

提交回复
热议问题