How to post to a Facebook page using the PHP SDK (5.0)?

1

I'm developing an application to schedule hourly publications for my Facebook page, I'm already able to log in the user get user access Token ID and everything, I have the necessary permissions in the Facebook application, and I already have

I need to get the list of pages that the user manages, get the access token (prolonged) 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 legend).

Could anyone help me?

    
asked by anonymous 15.12.2016 / 16:36

1 answer

2

You have to generate a specific Token for . You have Facebook to do that.

After that they are the same processes for doing 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();
    
15.12.2016 / 16:41