Php – “An active access token must be used to query information about the current user” facebook error

facebookfacebook-access-tokenoauthPHP

I'm developing an app on Facebook and I'm having some problems.
Basically, after the user wins the game, I'm asking him to post his success on his wall (like "Look! I won the game! Play this game too on game's name!" -> this is the translation of the Romanian bits of the following code). I'm using this code:

if ($raspuns == "Yer Blues") {

echo("Bravo! Ai castigat jocul! Intoarce-te saptamana viitoare cand
se va posta un alt set de melodii!");

$access_token = $facebook->getAccessToken();

$wall_post = array('message' => 'Am castigat jocul Ghiceste Melodia!
Joaca si tu cu Revista Floyd!',

            'name' => 'Campion Ghiceste Melodia',

            'caption' => "Am castigat jocul Ghiceste Melodia! Joaca si tu cu Revista Floyd!",

            'link' => 'https://apps.facebook.com/revistafloyd/',

            'description' => 'Revista Floyd este o revista despre muzica rock.',

            );    

$result = $facebook->api('/me/feed/', 'post', $wall_post);

}

But I get this message whenever the user inputs the right answer:

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /home/pasarel/public_html/face/src/base_facebook.php on line 1106

Why is that? I mention that I'm having both user and app access token, so what's wrong?
I read somewhere that it may be missing the "session" part, (here: http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/ ). May this be the answer? How do I fix it?

Best Answer

Simply

Change this

$wall_post = array('message' => 'Am castigat jocul Ghiceste Melodia! Joaca si tu cu Revista Floyd!',

            'name' => 'Campion Ghiceste Melodia',

            'caption' => "Am castigat jocul Ghiceste Melodia! Joaca si tu cu Revista Floyd!",

            'link' => 'https://apps.facebook.com/revistafloyd/',

            'description' => 'Revista Floyd este o revista despre muzica rock.',

            );    

to this

$wall_post = array('access_token' => $access_token ,
'message' => 'Am castigat jocul Ghiceste Melodia! Joaca si tu cu Revista Floyd!',

            'name' => 'Campion Ghiceste Melodia',

            'caption' => "Am castigat jocul Ghiceste Melodia! Joaca si tu cu Revista Floyd!",

            'link' => 'https://apps.facebook.com/revistafloyd/',

            'description' => 'Revista Floyd este o revista despre muzica rock.',

            );    

Update

Try to change this

$WallPost = array(
                        'access_token' => $access_token,
                        'message' => $message,
                        'link' => $link,
                        'name' => $name,
                        'caption' => $caption,
                        'description' => $description);

                        $response = $facebook->api('/me' . '/feed','POST',$WallPost);
Related Topic