How to publish to a Facebook page using the PHP SDK (5.0)?
Facebook facebook page
I am developing an application to schedule publications from time to time for my Facebook page, I can already log in the user get ID Token access of the user and everything else, I have the necessary permissions in the Facebook application, and I have even managed to post messages with image in the user's profile, but I did not get anything related to pages, all the codes I found did not work.
I need to get the list of pages that the user manages, get the Access token(Extended) of a certain page and publish photos on Facebook with the profile of the page (I do not want to publish links, I want to publish only images with caption).
Could anyone help me?
1 answers
You have to generate a Token specific for Page. Have Facebook to do that.
After that are the same processes for making a post in a profile, with the difference in the URL.
$fb = new Facebook\Facebook([
'app_id' => [APP_ID],
'app_secret' => [APP_SECRET],
'default_graph_version' => 'v2.7',
]);
$linkData = [
'link' => '',
'caption' => '',
'description' => '',
'name' => '',
'message' => '',
'picture' => ''
];
$pageAccessToken ='';
try {
$response = $fb->post('/NOME_DA_PAGE/feed', $linkData, $pageAccessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
exit;
}
$graphNode = $response->getGraphNode();