Hi, I am using google-ads-api to fetch campaign performance data, but I was stop by the following error.
"message": "The caller does not have permission", "code": 7, "status": "PERMISSION_DENIED"
$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile("google_ads_php.ini")->build();
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile("google_ads_php.ini")
->withOAuth2Credential($oAuth2Credential)
->withLoginCustomerId($customerId)
->build();
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$customerServiceClient = $googleAdsClient->getCustomerServiceClient();
// Issues a request for listing all accessible customers.
$accessibleCustomers = $customerServiceClient->listAccessibleCustomers();
print 'Total results: ' . count($accessibleCustomers->getResourceNames()) . PHP_EOL;
// Iterates over all accessible customers' resource names and prints them.
foreach ($accessibleCustomers->getResourceNames() as $resourceName) {
printf("Customer resource name: '%s'%s", $resourceName, PHP_EOL);
$customer_id = explode("/", $resourceName)[1];
$stream = $googleAdsServiceClient->search($customer_id, $query);
echo json_encode($stream);
foreach ($stream->iterateAllElements() as $googleAdsRow) {
printf(
"Campaign with ID %d and name '%s' was found.%s",
$googleAdsRow->getCampaign()->getId(),
$googleAdsRow->getCampaign()->getName(),
PHP_EOL
);
}
}
My question is how to specify login-customer-id in the request by php. And what's reason about this error.