0

Hello I created an API to post directly, it works very well on my facebook profile, the status is ok when I try to publish a status in my page, the post goes in the visitors publications what do I do ?

I looked in the Facebook Graph API, it would seem that this is a bug .. that you can bypass with using Curl..?

ps/ I edited the information page id, app id, secret app

Thanks in advance for your help Stéphanie

public function statutPage(){

    $fb = new Facebook([
        'app_id' => 'my app id',
        'app_secret' => 'my app secret',
        'default_graph_version' => 'v2.8',

    ]);

    $pageID='my page id,;
    $token='A_VALID_USER_ACCESS_TOKEN';

    $attachment = [
        'access_token' => $token,
        'message' => 'Premier message auto',
        'name' => 'Première publication sur facebook',
        'caption' => 'Legend sous le tire',
        'link' => 'https://www.la-programmation.surleweb-france.fr',
        'description' => 'Description du lien',
        'picture' => 'https://www.google.fr/images/srpr/logo11w.png'
    ];


    try {
        $response = $fb->post('/'.$pageID.'/feed/', $attachment);

    } catch(FacebookAuthorizationException $e) {
        echo 'Graph retourne une erreur: ' . $e->getMessage();
        exit;
    } catch(FacebookSDKException $e) {
        echo 'Facebook SDK retourne une erreur: ' . $e->getMessage();
        exit;
    }

    $graphNode = $response->getGraphNode();

    echo 'Posté su Facebook avec l\'id: ' . $graphNode['id'];

}
  • Please edit your question to provide some `code samples` **and** provide the scenario you want to achieve. Also look into the Facebook Graph API documentation itself. It's probably necessary to provide alternative parameters to achieve the effect you want it to have. – Yves Schelpe Feb 26 '17 at 08:16
  • _"I looked in the Facebook Graph API, it would seem that this is a bug"_ - nonsense. In fact, you did not read the documentation carefully enough. https://developers.facebook.com/docs/graph-api/reference/v2.8/page/feed#publish – CBroe Feb 27 '17 at 08:45
  • Thanks for your reply, I read and reread the documentation but this does not work on a page ... on a profile no problem! For the moment I have not found the solution to publish a status on a page ... – Stéphanie Caumont Feb 27 '17 at 08:48

1 Answers1

0

note apparanlty code below only works for "user profiles" and not for "pages". If you want info on how to handle pages, please look into the answer given at Facebook SDK v5 Post as Page on Wall!


But with that being said, Reading the Facebook PHP Developers Docs for publishing to a feed on Graph API 5.0, I see they're use the FacebookRequest object and then executing the method execute on it. It however returns a GraphObject - which seems deprecated in versions higher than 4.

They also mention to be sure to have publish_actions permissions on the account you're logged in with to auto post.

Reference PHP SDK code from facebook /feed/ SDK docs (in the url scroll down to 'publishing') for Graph API 5.0 - note that it returns a GraphObject - which seems deprecated in versions higher than 4. - I edited the example to use getGraphNode as referred to in https://developers.facebook.com/docs/php/FacebookRequest/5.0.0.

/* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'POST',
  '/me/feed',
  array (
    'message' => 'This is a test message',
  )
);
$response = $request->execute();
$graphNode = $response->getGraphNode();
/* handle the result */

Alternatively they also mention using the graph api directly by link to Publish with Graph API.

Community
  • 1
  • 1
Yves Schelpe
  • 3,343
  • 4
  • 36
  • 69