How do I publish to a Facebook page using the PHP SDK (5.0)?

Asked

Viewed 707 times

1

I’m developing an application to schedule hourly posts for my Facebook page, I can already log the user get User Access ID Token and everything else, I have the necessary permissions in the Facebook app, and I’ve been able to post image messages on the user’s profile, but I couldn’t get anything related to pages, all the codes I found didn’t work.

I need to get the list of pages that the user manages, get the access token (extended) of a given page and publish photos on Facebook with the page profile (I do not want to publish links, I want to publish only images with caption).

Could someone help me?

1 answer

2


You have to generate one Token specific to page. There is on Facebook to do this.

After that are the same processes to make a POST on 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();
  • Thank you! I was able to post using a token obtained at https://developers.facebook.com/tools/explorer/ but this token only lasts one hour. You know how to get a token within the application itself?

  • There is a place where you take the Eternal Token, read the page that takes the Token... https://developers.facebook.com/tools/debug/token

  • This eternal token stop by what I researched was discontinued, the current tokens last for about two months, the 2 month token already helps me, but the ideal would be to get a token by the application itself,I will continue searching here, thank you very much!

  • Man, I use one here... never gave problem, since June.

  • You have to click the button Extends Access Token. When click will appear a sentence and a Token. This new long-lived access token will Never expire:

  • I got the eternal access token for the page, it was really worth @Gumball You have an answer for this question > http://answall.com/questions/172745/howto mention-uma-pagina-ou-perfil-do-facebook-com-sdk-php

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.