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.

2 Answers 2

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

3
  • I think OP is doing the same. Commented Nov 27, 2013 at 6:37
  • Does the paga access token expire like the user tokens?
    – Mr A
    Commented Nov 27, 2013 at 6:41
  • Could you please read the whole document? The answer's already in there.
    – C3roe
    Commented Nov 27, 2013 at 7:05
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.

2
  • I added it in the facebook settings.
    – Mr A
    Commented Nov 27, 2013 at 6:41
  • No, not in the App Settings, that wont affect what permissions will be asked from the user. Add them to the login code using scope parameter Commented Nov 27, 2013 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.