Search code examples
facebookfacebook-graph-apifacebook-php-sdk

Facebook API 2.2 - me/accounts - returns array(0)


I'm actually having troubles with the graph API :

https://developers.facebook.com/tools/explorer?method=GET&path=me%2Faccounts&version=v2.2&

I've been generating an access token with the extended permission 'manage_pages' and i'm trying a request on the edge 'me/accounts'. The result is always :

{
  "data": [
  ]
}

But I wished to get a page access token instead. Is this a normal behavior, or did I miss something?


I also tried with the php SDK 4.0 with a short-lived and a long-lived token and got the same result... My code is here:

$app_id             = '-hidden-';  //Facebook App ID
$app_secret         = '-hidden-';  //Facebook App Secret    
$long_lived_token   = '-hidden-';  // tested at https://developers.facebook.com/tools/debug/ 
                                   //and giving  - Expires :1429438313 (in about 2 months) 

FacebookSession::setDefaultApplication($app_id , $app_secret);
$session = new FacebookSession($long_lived_token);

if ($session) { 
    try {
        $user_permissions = (new FacebookRequest($session, 'GET', '/me/permissions'))
            ->execute()->getGraphObject(GraphUser::className())->asArray();

        $found_permission = false;
        foreach($user_permissions as $key => $val){        
            if($val->permission == 'manage_pages'){
                $found_permission = true;
            }
        }

        // if we got manage_pages
        if($found_permission){
            $user_token = (new FacebookRequest($session, 'GET', '/me/accounts'))
                ->execute()->getGraphObject(GraphUser::className())->asArray();
            var_dump($user_token); //array(0) { }  -  Why?? Is this normal??
        } else {
            echo "Manage pages not granted!";
        }

    } catch(FacebookRequestException $e) {
        echo "Exception occured, code: " . $e->getCode();
        echo " with message: " . $e->getMessage();
    } 
}

Thanks for your help!


Solution

  • My user didn't have any pages to admin, this is why the array is empty. I guessed page access token could be use to manage profile but I was wrong.