0
votes

I've got problems with posting from PHP on Facebook PAGE wall. Same code posts for my personal account (admin on that Facebook page) - but without success when i trying to post on Page.

code working to post on user wall $linkData = [ 'link' => 'http://www.somewebpagelink.com', 'message' => 'User provided message', 'description' => 'test', 'caption' => 'caption', 'published' => 'true' ];

    try {
      // Returns a `Facebook\FacebookResponse` object
      $response = $fb->post('me/feed', $linkData, $accessToken);
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e->getMessage();
      exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e->getMessage();
      exit;
    }

    $graphNode = $response->getGraphNode();

    echo 'Posted with id: ' . $graphNode['id'];

But when i've change

$response = $fb->post('https://graph.facebook.com/{valid_page_id}/feed', $linkData, $accessToken);

Where valid_page_id is my real page id, it doesn't post on Facebook page.

Can someone help ?

Ps. Defined app is public, user i've used as login had admin privileges to this page.

Thanks!

1
You need to use a page access token to post on the page as the page - WizKid
@WizKid - I've get it using this: $response = $fb->get('/me/accounts'); $json = json_decode($response->getBody(),true); $page_token = $json['data']['0']['access_token']; Where [0] is the page i've want to post. $response = $fb->post('http://graph.facebook.com/{my_page_id}/feed', $linkData, $page_token); Without success :-( - Grzegorz Miśkiewicz

1 Answers

0
votes

I found solution. It's easy. If someone need it:

$response = $fb->post('{page_id}/feed', $linkData, $page_token);

This is only thing i must to do, to post on Facebook page :-)