0

I am trying to post on a page I administered in Facebook and I use this code.

$fb_key['key'] = 'fb_access_token';
$access = Model_const::read_key($fb_key);
$f = new facebook\fb($cfg);
$f->setAccessToken($access['value']);

$p = 'User is not logged in';
if($f->getUser())
{
   $page_arg['access_token'] = $f->getAccessToken();
   $page_arg['fields']        = 'access_token';
   $page_info = $f->api("/$fb_id",'get',$page_arg);

   $fb  = array();
   $fb['link'] = $uri;
   $fb['message'] = Input::post('content');
   $fb['access_token'] = $page_info['access_token'];

   $p = $f->api("$fb_id/feed",'POST',$fb);
}

I followed this thread here and it appears that $page_info part is not recognized by the FB api. Reading on the documentation didn't help, though I can post using my personal account. I would like to have it on my facebook non-human page.

I was hoping if someone could provide how to do it via PHP SDK.

Community
  • 1
  • 1
Mr A
  • 1,205
  • 4
  • 19
  • 49

2 Answers2

0

Actually you have to retrieve the page access token from the admin user account here is a link to the documentation https://developers.facebook.com/docs/facebook-login/access-tokens/#pagetokens

Amine Matmati
  • 303
  • 1
  • 9
0

I think you are missing the permission : manage_pages

Add this permission with your login code.

  • If you are using getLoginUrl(), see here

  • If using the direct auth dialog url, add like this:

    $dialog_url= "http://www.facebook.com/dialog/oauth?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode( $post_login_url) . "&scope=manage_pages";

Another thing, if you want to extend page access token that never expires, I've explained the same in this thread: What are the Steps to getting a Long Lasting Token For Posting To a Facebook Fan Page from a Server

The rest seems to be correct. Good luck.

Community
  • 1
  • 1
Sahil Mittal
  • 20,351
  • 12
  • 59
  • 88