1
I created an application with the Facebook API for a company I work for. Fact is that everything works perfectly until the Logout part of the user. Every time you drop, the following error happens:
FacebookApiException Object
(
[result:protected] => Array
(
[error] => Array
(
[message] => An active access token must be used to query information about the current user.
[type] => OAuthException
[code] => 2500
)
)
The facebook scripts in my index.php is as follows:
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'x42xxx7191xxxxxx',
'secret' => 'xxxxbb2ce7xxxxxx472xxxx2fxf38xxx',
'cookie' => true,
));
// See if there is a user from a cookie
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
echo ''.htmlspecialchars(print_r($e, true)).'
';
$user = null;
}
}
if ($me) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
and also the following code:
window.fbAsyncInit = function() {
FB.init({
appId: 'getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(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);
}());
My logout code is as follows:
$logoutUrl = $facebook->getLogoutUrl(); echo 'Deslogar';
Remembering that it even depresses the user, gives a refresh on the page correctly but before the content of the page, it informs the error at the beginning of the text.