Skip to content
Advertisement

Graph returned an error: (#200) Permissions error

when I publish a post to my page, it’s working fine, but when I post to page through set page ID instead of “me”, the response as the following: Graph returned an error: (#200) Permissions error the source code as the following:

require_once 'src/Facebook/autoload.php';

//*
$config = array();
$config['appId'] = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$config['app_id'] = $config['appId'];
$config['secret'] = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$config['app_secret'] = $config['secret'];
define('APP_ID', $config['appId']);
define('APP_SECRET', $config['secret']);
//$config['fileUpload'] = false; // optional
$config['default_graph_version'] = 'v2.5'; 
$config['page_id']  =   'xxxxxxxxxxxxxxxxxxxxxxxx';  

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

$fb = new FacebookFacebook($config);




if(isset($_SESSION['fb_access_token'])) {
    $accessToken = $_SESSION['fb_access_token'];

} else {

    $helper = $fb->getRedirectLoginHelper();
    try {
        $accessToken = $helper->getAccessToken();

        if(isset($accessToken)) {
            $oAuth2Client = $fb->getOAuth2Client();

            // longlived access token
            if (!$accessToken->isLongLived()) {
                $accessToken = $oAuth2Client->getLongLivedAccessToken($accessToken); 
            }
        }

    } catch(FacebookExceptionsFacebookResponseException $e) {
        echo 'Graph returned an error: ' . $e->getMessage();
        exit;
    } catch(FacebookExceptionsFacebookSDKException $e) {
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        exit;
    }
}



if(isset($accessToken)) {
    // Logged in!
    $_SESSION['fb_access_token'] = (string) $accessToken;

    try {
        $response = $fb->get('/'.$config['page_id'].'/feed', $accessToken);

    } catch(FacebookExceptionsFacebookResponseException $e) {
        echo 'Graph returned an error: ' . $e->getMessage();
        //exit;
    } catch(FacebookExceptionsFacebookSDKException $e) {
        echo 'Facebook SDK returned an error: ' . $e->getMessage();
        //exit;
    } 
} else {
    $helper = $fb->getRedirectLoginHelper();

    $redirect_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $loginUrl = $helper->getLoginUrl($redirect_url, [ 'manage_pages', 'publish_pages', 'publish_actions' ]);
    echo '<a href="' . $loginUrl . '">Log in with Facebook!</a>';
}





on other action in same page 


$page_access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';







// instance
$fb = new FacebookFacebook([
    'app_id'     => APP_ID,
    'app_secret' => APP_SECRET,
    'default_graph_version' => 'v2.4',
]);

$linkData = [
  'link' => encodeurl(array('page'=>'page','lang'=>'ar','id'=>$_id,'beg'=>0,'unuse'=>$xtitlex)),
  'message' => $xtitlex,
  'source' => $publish,//$fb->fileToUpload($publish),
  'caption' => DOMAIN_,
  "picture" => $publish,
  "name" => $xtitlex,
  "description" => $xdescriptionx
 ];



try {
    //
    $response = $fb->post('/'.$config['page_id'].'/feed', $linkData, $page_access_token);

} catch(FacebookExceptionsFacebookResponseException $e) {
    //print_r($linkData);
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
}
?>

Advertisement

Answer

Most likely, you are not using a Page Token with the correct permissions. Make sure you are using a Page Token instead of a User Token and make sure it includes publish_pages. You can test your Token in the debugger: https://developers.facebook.com/tools/debug/

Make sure the Page ID shows up, and the publish_pages permission.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement