Error (#210) A page access token is required to request this resource

6.9k Views Asked by At

I'm trying to change the image of cover of a fanpage using the Facebook API.

I can interact with other actions, such upload an image, but I can not update it. I follow the example of documentation (https://developers.facebook.com/docs/graph-api/reference/v2.2/page?locale=es_LA) but I get the error: "(# 210) A page access token is required to request this resource. "

I got the page access token, but I can not use it. I leave part of the code:

<?php
require_once __DIR__ . "/facebook-php-sdk-v4-4.0-dev/autoload.php";

use Facebook\FacebookSession;
use Facebook\FacebookRequest;
use Facebook\GraphUser;

FacebookSession::setDefaultApplication($my_app_id , $my_app_secret);

try {
    $session = new FacebookSession("my-app-token");
}catch(Exception $e){
    // error with creation of session
}

if ($session){
    // set uploaded photo as cover image
    try{            
        $request = new FacebookRequest(
            $session,
            'POST',
            '/'.$page_id,
            array (
                'about' => 'string-about',
                'hours' => 'string-hour',
                'cover' => 'int-image-id',
                'offset_y' => '0',
                'no_feed_story' => true
            )
        );
        $response = $request->execute();
        $graphObject = $response->getGraphObject();
    }catch(Exception $e){
        // error changing the cover image
        /*
        {
            "error": {
                "message": "(#210) A page access token is required to request this resource.", 
                "type": "OAuthException", 
                "code": 210
            }
        }
        */
    }
}else{ 
    // no session
}
?>

From already thank you very much and sorry for my English.

0

There are 0 best solutions below