This question is a cross-post of an issue on the Github googleads/google-ads-php library, I was told to follow up here for more help.
I am working to get a product integrated with the Google Ads Conversion Actions. We are attempting to add new conversion actions via the Google Ads API (v2). We have followed the instructions for such an action, as documented here.
Of course our code looks a little different, so here is an excerpt of it:
// An oAuth token previously obtained. We do have a refresh token.
// This token has been granted the following scope:
// https://www.googleapis.com/auth/adwords
// as documented at:
// https://developers.google.com/adwords/api/docs/guides/authentication
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId('REDACTED')
->withClientSecret('REDACTED')
->withRefreshToken('REDACTED')
->build();
// The ID of the client website
// The user granting us their oAuth token has full access to this property
// Our MCC account also has full permissions for this account for good measure
$customerId = 'xxx-xxx-xxxx';
$googleAdsClient = (new GoogleAdsClientBuilder())
// This developer token was obtained from our MCC account, as documented here:
// https://developers.google.com/google-ads/api/docs/first-call/dev-token
->withDeveloperToken('REDACTED')
->withLoginCustomerId($customerId)
->withOAuth2Credential($oAuth2Credential)
->build();
// Just setting up a test conversion action
$conversionAction = (new ConversionAction())
->setName((new StringValue())->setValue('TEST LABEL'))
->setCategory(ConversionActionCategory::PBDEFAULT)
->setType(ConversionActionType::WEBPAGE)
->setStatus(ConversionActionStatus::ENABLED)
->setValueSettings(
(new ValueSettings())
->setAlwaysUseDefaultValue((new BoolValue())->setValue(true))
->setDefaultValue((new DoubleValue())->setValue(0.0))
);
// Issues a mutate request to add the conversion action.
$conversionActionServiceClient = $googleAdsClient->getConversionActionServiceClient();
$response = $conversionActionServiceClient->mutateConversionActions(
$customerId, [(new ConversionActionOperation())->setCreate($conversionAction)]
);
// That causes the exception we are seeing
At that last function call, we get an authentication exception that looks like this:
Google\ApiCore\ApiException : {
"message": "Request had insufficient authentication scopes.",
"code": 7,
"status":
"PERMISSION_DENIED",
"details": []
}
Now as far as we can tell, all the pieces are properly authorized. Any pointers? Anything obvious we are doing wrong?
Hi Judah,
Can you please reply privately to author your API call request and response so I can take a closer look?
Thanks,
Anthony
Google Ads API Team
[2020-02-12 15:39:45] local.ERROR: {
"message": "Request had insufficient authentication scopes.",
"code": 7,
"status": "PERMISSION_DENIED",
"details": []
} {"exception":"[object] (Google\\ApiCore\\ApiException(code: 7): {
\"message\": \"Request had insufficient authentication scopes.\",
\"code\": 7,
\"status\": \"PERMISSION_DENIED\",
\"details\": []
} at /redacted/vendor/google/gax/src/ApiException.php:139)
Thanks for trying. Could you please continue communicating with the agent on the forum? Thanks.