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"

My PHP code: 
```
$customerId = "Manager ID";
$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];

$query = "SELECT campaign.id, campaign.name, campaign.status FROM campaign 
ORDER BY campaign.id";
$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
);
} 
}
```

The error in log: 
```
[2021-08-16T08:07:56.532753+00:00] google-ads.INFO: Request made: Host: 
"googleads.googleapis.com", Method: 
"/google.ads.googleads.v6.services.CustomerService/ListAccessibleCustomers", 
CustomerId: "No customer ID could be extracted from the request", 
RequestId: "Vq8FGtFRDS9D-Id2aMRSzQ", IsFault: 0, FaultMessage: "None" 
[2021-08-16T08:07:56.672678+00:00] google-ads.WARNING: Request made: Host: 
"googleads.googleapis.com", Method: 
"/google.ads.googleads.v6.services.GoogleAdsService/Search", CustomerId: 
3452842817, RequestId: "4waISQvRlXbmTrAbjBSvoQ", IsFault: 1, FaultMessage: 
"["User doesn't have permission to access customer. Note: If you're 
accessing a client customer, the manager's customer id must be set in the 
'login-customer-id' header. See 
https:\/\/developers.google.com\/google-ads\/api\/docs\/concepts\/call-structure#cid"]"
 
[2021-08-16T08:07:56.673119+00:00] google-ads.NOTICE: Request ------- 
Method Name: /google.ads.googleads.v6.services.GoogleAdsService/Search 
Host: googleads.googleapis.com Headers: { "x-goog-api-client": 
"gl-php\/7.4.3 gapic\/ gax\/1.7.0 grpc\/1.36.0", "x-goog-request-params": 
"customer_id=3452842817", "developer-token": "REDACTED" } Request: 
{"customerId":"3452842817","query":"SELECT campaign.id, campaign.name, 
campaign.status FROM campaign ORDER BY 
campaign.id","pageSize":1000,"returnTotalResultsCount":true} Response 
------- Headers: { "request-id": "4waISQvRlXbmTrAbjBSvoQ", "date": "Mon, 16 
Aug 2021 08:07:56 GMT", "alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; 
ma=2592000,h3-T051=\":443\"; ma=2592000,h3-Q050=\":443\"; 
ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; 
ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"" } Fault ------- Status 
code: 7 Details: The caller does not have permission Failure: 
{"errors":[{"errorCode":{"authorizationError":"USER_PERMISSION_DENIED"},"message":"User
 
doesn't have permission to access customer. Note: If you're accessing a 
client customer, the manager's customer id must be set in the 
'login-customer-id' header. See 
https://developers.google.com/google-ads/api/docs/concepts/call-structure#cid"}]}
```

My question is how to specify login-customer-id in the request by php. And 
what's reason about this error.

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/a48bdf03-1b29-41c6-80eb-de31ff2bf969n%40googlegroups.com.

Reply via email to