Facebook API problems

1

I've created an application with the Facebook API for a company I work for. Fact is that everything works perfectly up to the Logout part of the user. Every time you scroll, the following error occurs:

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 are 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);
        }());

The code for my logout is as follows:

$logoutUrl = $facebook->getLogoutUrl();
echo 'Deslogar';

Remembering that it even displaces 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.

    
asked by anonymous 14.08.2014 / 17:11

1 answer

1

I believe you need to change the cookie to expire, so the error is happening. I do not know PHP anymore for my program I developed a Python algorithm that performs Logout. Below my Python solution

class LogoutHandler(BaseHandler):
    def get(self):
        set_cookie(self.response, "fb_user", "", expires=time.time() - 86400)

    self.redirect("/")

You will find this example useful for your application.

    
14.08.2014 / 18:46