I implement the facebook in my wordpress website and everything is working ok except one situation.

If I logout from facebook, and then I click logout in website, I get the error:

FB.logout() called without an access token.

So I replace the logout code with this:

return javascript:if(FB.getAccessToken()){FB.logout(function(){location.href='" . $url . "'})}else{location.href='" . $url . "'}";

(This is done in a wordpress hook, so that I can have the wordpress logout url)

But now, when I click logout in this situation I get a js error:

Unsafe JavaScript attempt to access frame...

How can I be able to logout safely from facebook and wordpress. FB.Logout doesn't have an error callback and doesn't throw any js error, so it's difficult to check that situation.

Thank you!

有帮助吗?

解决方案

You need to get the login status first from Facebook, and only if logged in can you call FB.logout. Try the following code.

FB.getLoginStatus(handleSessionResponse);

function handleSessionResponse(response) {

    //if we dont have a session (which means the user has been logged out, redirect the user)
    if (!response.authResponse) {
        return;
    }

    //if we do have a non-null response.session, call FB.logout(),
    //the JS method will log the user out of Facebook and remove any authorization cookies
    FB.logout(response.authResponse);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top