Php – Error (#200) The user hasn’t authorized the application to perform this action facebook graph api php codeigniter

codeigniterfacebookfacebook-graph-apifacebook-php-sdkPHP

Here are my permissions

$config['facebook']['permissions'] = array(
  'email',
  'user_location',
  'user_birthday',
  'publish_actions',
  'manage_pages',
  'public_profile',
);

I can not post on a facebook page as a admin. It gives me this error

Exception occured, code: 200 with message: (#200) The user hasn't authorized the application to perform this action

if I remove 'access_token' => $pageList['access_token'], then I can post on the page but not as a admin.but when I add this line it gives me this above error can anyone tell me why
Here is my function pagePost which I am using to post on a page

 public function pagePost() {
    if ( $this->session ) {

    try {

      $pageAccessToken;
      $request_page = new FacebookRequest($this->session, 'GET', '/1420447421611683?fields=access_token,name,can_post');
      $pageList = $request_page->execute()
        ->getGraphObject()
        ->asArray();

      $request = ( new FacebookRequest( $this->session, 'POST', '/1420447421611683/feed',array(
                    'access_token'  => $pageList['access_token'],
                    'link' => 'www.example.com',
                    'message' => 'Hello Up',
                  ) ) )->execute();
        echo "Posted with id: " . $request->getProperty('id');

        $page = $request->getGraphObject()->asArray();
      return $page;
    } catch(FacebookRequestException $e) {
            echo "Exception occured, code: " . $e->getCode();
            echo " with message: " . $e->getMessage();
      }
    }
    return false;
  }

What is wrong?

Best Answer

To post to a Page "as Page", you need to authorize the user with "publish_pages" and you need to use a Page Token. Try to add publish_pages to your permission list:

$config['facebook']['permissions'] = array(
  'email',
  'user_location',
  'user_birthday',
  'publish_actions',
  'publish_pages',
  'manage_pages',
  'public_profile',
);
Related Topic