Unsupported get request using Ads Facebook SDK for PHP -


i'm trying access ads campaigns related data (such country, cpm, spent ...) using facebook php-ads-sdk

the facebook user added admin in facebook bussiness manager.

the first thing access token given app_secret , app_id of user:

public function getaccesstoken() {     try {         $response = $this->client->get(             $this->accesstokenurl, [             'query' => [                 'client_id' => $this->appid,                 'client_secret' => $this->appsecret,                 'grant_type' => 'client_credentials',             ],             'stream' => true         ]);     } catch(requestexception $e) {         echo $e->getmessage();     }      $body = $response->getbody();     $contents = $body->getcontents();      $contentsarray = explode('=', $contents);      return $contentsarray[1]; } 

it comes in form:

access_token=xxxxxx

that's why have make explode.

once got access token, authenticate in api:

api::init($this->appid, $this->appsecret, $this->accesstoken); $api = api::instance(); 

finally try data using bussiness manager account id:

$account = new adaccount($this->accountid); $test = $account->getadcampaigns(); 

but following error message:

[facebookads\http\exception\authorizationexception]
unsupported request. please read graph api documentation

any suggestions?

update:

as suggested in first comment paul bain, changed these lines:

$account = new adaccount($this->accountid); $test = $account->getadcampaigns(); 

for these ones:

$account = new adaccount('act_' . $this->accountid); $test = $account->getadcampaigns(); 

and different error message:

(#10) not have sufficient permissions perform action

i don't know why don't have sufficient permissions, since said before user added admin in facebook bussiness manager.

also in facebook user profile, under settings/advanced, facebook bussiness manager account id added in 'authorized ad account ids'

the app approved basic access level.

you need prefix id of adaccount trying access act_ otherwise not work.

for example, if following, see ids of adaccounts prefixed way in api response:

use facebookads\object\aduser; $user = new aduser('me'); $accounts = $user->getadaccounts(array('name')); foreach($accounts $act) {   echo $account->id." - ".$account->name.php_eol; } 

Comments