I have an application which I use to post as a page on the Facebook page itself. I want to know how can I get the access token dynamically (because it expires every hours or 60 days).
Here's the code I use :
$facebook = new \Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXX'
));
try {
$page_id = 'XXXXXXXXXXXXXXXXXXXXX';
$page_info = $facebook->api("/$page_id?fields=access_token");
$page_info['access_token'] = "XXXXXXXXXXXXXXXXXXXXX"; // HERE'S THE PROBLEM !!
$args = array(
'access_token' => $page_info['access_token'],
'message' => "My message !"
);
$post_id = $facebook->api("/$page_id/feed","post",$args);
} catch (FacebookApiException $e) {
error_log($e);
}