phpfacebookfbconnect

Exception occured, code: 200 with message: (#200) Permissions error


I have a problem with FB PHP SDK. Here is my code:

require_once("autoload.php"); // set the right path

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphObject;
use Facebook\FacebookRequestException;

$APP_ID = 'APP_ID';
$APP_SECRET = 'APPSECRET';
$TOKEN = "TOKEN";
$ID = "PAGE_ID"; // your id or facebook page id

FacebookSession::setDefaultApplication($APP_ID, $APP_SECRET);

$session = new FacebookSession($TOKEN);

$params = array(
"message" => "Xoşbəxt olmamaq haqsızlıq deyilmi özümüzə qarşı?!"
);


if ($session) {
try {
    $response = (new FacebookRequest(
            $session, 'POST', '/' . $ID . '/feed', $params
            ))->execute()->getGraphObject();
    echo "Posted with id: " . $response->getProperty('id');
} catch (FacebookRequestException $e) {
    echo "Exception occured, code: " . $e->getCode();
    echo " with message: " . $e->getMessage();
}
}

But when i try to run this code it returns an error: Exception occured, code: 200 with message: (#200) Permissions error

in some forums i read that may be i need to approve premissons/ but when i submited premissions to FB they answered that if i am using it only for my purpose (as app admin) premisson approval is not requred.

What can be problem?


Solution

  • Debug your Access Token: https://developers.facebook.com/tools/debug/

    Make sure it includes the manage_pages and publish_pages permission. And make sure you are using a Page Token. More information about the different Tokens: