Reputation: 1064
I've already searched among the other questions here on Stackoverflow and on other websites, but I couldn't find a solution, also because it seems that FB often changes the authentication method, so old solutions are no more valid.
I'm using SDK4 and this is my code as I have it at the moment
FacebookSession::setDefaultApplication($app_id, $app_secret);
$session = FacebookSession::newAppSession();
try {
$session->validate();
} catch (FacebookRequestException $ex) {
echo $ex->getMessage();
} catch (\Exception $ex) {
echo $ex->getMessage();
}
if($session)
{
try {
$response = (new FacebookRequest(
$session, 'POST', '/me/feed', array(
'link' => 'www.mysite.it',
'message' => 'some text'
)
))->execute()->getGraphObject();
echo "Posted with id: " . $response->getProperty('id');
} catch(FacebookRequestException $e) {
echo "Exception occured, code: " . $e->getCode() .
" with message: " . $e->getMessage();
}
}
I get this message:
"Exception occured, code: 2500 with message: An active access token must be used to query information about the current user."
Given the message, the session is correctly created and validated, the problem is on the execute() method, how do I fix it?
Upvotes: 0
Views: 36
Reputation: 314
It looks like you've created your session for your app, but to post on a users behalf you need to get an access token for said user and then call
$this->facebook = new FacebookSession($access_token);
Upvotes: 1