Google Ads Api Developer Token Error - even though it is validated
I am developing an application which integrates with Google Ads and syncing Ad/Campaign etc. data into my servers. I am getting authorization related error when I try to request some data from Google Ads API. Here is the steps I have done by now:
- Applied to Google in terms of validating an OAuth application and scopes (Done, we got verification from Google and can ask for AdWords scope)
- Applied to Google Ads for getting a developer token and got it. (Basic Access)
- We are able to connect test accounts and successfully getting the response. But when we try it with real accounts we get the error below.
The code is also from the original Google Ads API example. I have tried with tons of different accounts but none of them seems to be working. When I try to obtain those data with same parameters from AdWords API instead of Google Ads API, it works. But Google AdWords PHP SDK is no longer maintained so I have to keep trying with Google Ads API. I share my code below:
{ $this->customerId = $customerId; $this->clientId = $clientId; $this->clientSecret = $clientSecret; $this->accessToken = $accessToken; $oAuth2Credential = (new OAuth2TokenBuilder()) ->withClientId($this->clientId) ->withClientSecret($this->clientSecret) ->withRefreshToken($this->accessToken) ->build(); $this->googleAdsClient = (new GoogleAdsClientBuilder()) ->withOAuth2Credential($oAuth2Credential) ->withDeveloperToken(env("GOOGLE_DEVELOPER_TOKEN")) ->withLoginCustomerId((int) $this->customerId) ->build(); } public function getCampaigns(): array{ try { $campaigns = []; $services = $this->googleAdsClient->getGoogleAdsServiceClient(); $results = $services->search($this->customerId, $this->campaignQuery(), ['pageSize' => self::PAGE_SIZE]); foreach ($results->iterateAllElements() as $row) { $campaigns[] = (new Campaign())->transform($row); } return $campaigns; } catch (GoogleAdsException $googleAdsException) { // TODO add error log return []; } }``` The error: ```Google\ApiCore\ApiException: { "message": "The caller does not have permission", "code": 7, "status": "PERMISSION_DENIED", "details": [ { "@type": 0, "data": "type.googleapis.com\/google.ads.googleads.v6.errors.GoogleAdsFailure" }, { "@type": 0, "data": [ { "errorCode": { "authorizationError": "DEVELOPER_TOKEN_PROHIBITED" }, "message": "Developer token is not allowed with project '691752477594'." } ] } ]}```
Are you using the same cloud console project credentials for the login on your site as you are for the API calls?
The very first call to the Google Ads API permanently associates a developer token to a cloud project. If this is different to the one you're using on your site, you may have to switch them.
As said before you need to create a new google cloud project, this is related with how Google organises users through their products.
If you are a company that is advertising through Google Ads, Google wants you to organise all your campaigns under a single master user account. That master user account should have a single developer token which you use within the Google Cloud Project associated to the same company.
For Google you should not have multiple master user accounts for the same company and therefore multiple developer tokens.
Of course there are edge cases that do not fit this rule, like advertising agencies however there is not a large incentive for Google to change this.
You can follow this thread for updates, but I do not expect things to change any time soon, https://groups.google.com/g/adwords-api/c/O8_y2xt0nGo
some developer token is already associated with project that you are trying with, to resolve this You have to create one more App project in console and re configure your secrate key, and client id with new project that you have created dont forget to use the latest developer token i.e (your current developer token) and make a first API call, then your developer token will get paired forever, once it get bound it will never be changed later on.