Im building an app with google ads api using a *service account* auth flow 
(server to server). The problem - the auth part is not working...


*Sample of the request:*

const request = require('request');
 ....
 request({
   'method': 'GET', 'url': 
'https://googleads.googleapis.com/v6/customers/XXXXXXXX',    
   'headers': {
     'Authorization': 'Bearer XXXXXXXX', 
     'developer-token': 'XXXXXXXX', '
     Content-Type': 'application/json' }
 }) ...

*or using curl -> *

curl --location --request GET 
'https://googleads.googleapis.com/v6/customers/XXXXXXXX' \ --header 
'Authorization: Bearer XXXXXXXX' \ --header 'developer-token: XXXXXXXX' \ 
--header 'Content-Type: application/json'


*[ERROR] Response from google ads api:*

{ 
   "code": 401, 
   "message": "Request had invalid authentication credentials. Expected 
OAuth 2 access         token, login cookie or other valid authentication 
credential. See        
    
 https://developers.google.com/identity/sign-in/web/devconsole-project.";, 
   "status": "UNAUTHENTICATED"
 }

I can't seem to find out why I'm getting this authentication error.

What I have tried:

   1. Following this guide step by step -> 
   https://developers.google.com/google-ads/api/docs/oauth/service-accounts
   2. Using the python library -> 
   https://github.com/googleads/googleads-python-lib
   3. Using the google ads API with REST (no library)
   4. On localhost server
   5. On the production server (the www.g-suite.com domain linked to the 
   account)

Whatever method or environment I try, it results in the same error.



*Sample of how I create the access token (nodejs) -> this part works 
fine:*const 
{ google } = require('googleapis'); 

....

const getAccessToken = async () => {

    const SCOPES = ['https://www.googleapis.com/auth/adwords'];

    const authClient = new google.auth.GoogleAuth({

        keyFile: './pathtokeyfile.json',

        scopes: SCOPES,

    });

    const token = await authClient.getAccessToken();

    return token;

};

*Steps I have implemented:*

   - Created a google ads manager account
   - Generated a valid developer token for that account
   - Created project in Google cloud platform
   - Opened a service account inside the project
   - Created a private key for the service account
   - Granting impersonation abilities in the G Suite domain for this scope: 
*https://www.googleapis.com/auth/adwords 
   <https://www.googleapis.com/auth/adwords>*
   - Enabled domain-wide delegation on the service account
   - Generated the *access token* with the key JSON file.

*I am surely missing something, but am not sure what it is..*


Will be super grateful if someone can share a solution!! thanks champs 👍

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
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 adwords-api+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/650353ba-27c6-4aca-a136-314c95ce60b7n%40googlegroups.com.

Reply via email to