I'm trying to access ads campaigns related data (such as country, cpm, spent ...) using Facebook php-ads-sdk
The Facebook user is already added as admin in Facebook Bussiness Manager.
The first thing I do is get the access token given the app_secret and app_id of the 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 the form:
access_token=xxxxxx
That's why I have to make an explode.
Once I got the access token, I authenticate in the Api:
Api::init($this->appId, $this->appSecret, $this->accessToken);
$api = Api::instance();
Finally I try to get some data using the Bussiness Manager account id:
$account = new AdAccount($this->accountId);
$test = $account->getAdCampaigns();
But I get the following error message:
[FacebookAds\Http\Exception\AuthorizationException]
Unsupported get request. Please read the Graph API documentation
Any suggestions?
UPDATE:
As suggested in the first comment by Paul Bain, I changed these lines:
$account = new AdAccount($this->accountId);
$test = $account->getAdCampaigns();
For these ones:
$account = new AdAccount('act_' . $this->accountId);
$test = $account->getAdCampaigns();
And now I get a different error message:
(#10) You do not have sufficient permissions to perform this action
I don't know why I don't have sufficient permissions, since as I said before the user is added as admin in Facebook Bussiness Manager.
Also in the facebook user profile, under settings/advanced, the Facebook Bussiness Manager account id is added in 'Authorized Ad Account IDs'
The app is approved for Basic access level.