Google ads api Authorization

346 views
Skip to first unread message

Mehul Panchal

unread,
Jan 2, 2024, 1:29:17 AM1/2/24
to Google Ads API and AdWords API Forum
hi 

I need access token for access google ads api from server to server call. which api i used and what are the needed creds ?

Google Ads API Forum Advisor

unread,
Jan 2, 2024, 2:14:16 AM1/2/24
to mehul....@jambojar-tech.com, adwor...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads API support team.

After reviewing your concern, I understand that you need to access Google Ads API.

I would recommend you refer to the document Getting Started to get more information on how to do Google Ads API setup step by step. Also, you can refer to the guide Access Levels and Permissible Use to get more information on access levels. Please go through the supported Libraries and Examples for your reference. 

 
This message is in relation to case "ref:!00D1U01174p.!5004Q02r4kZ4:ref"

Thanks,
 
Google Logo Google Ads API Team


Mehul Panchal

unread,
Jan 2, 2024, 3:37:24 AM1/2/24
to Google Ads API and AdWords API Forum
Can i get refresh token from server to server ?

Google Ads API Forum Advisor

unread,
Jan 2, 2024, 7:12:32 AM1/2/24
to mehul....@jambojar-tech.com, adwor...@googlegroups.com
Hi,

Thank you for getting back to us.

Based on the information you have provided I understand that you are trying to get the refresh token. I would suggest you to refer to the Fetch a refresh token for more information.

Mehul Panchal

unread,
Jan 3, 2024, 2:54:02 AM1/3/24
to Google Ads API Forum Advisor, adwor...@googlegroups.com
i am generaing access token from below functions but getting error like this "The Google account (@gmail.com user) that generated the OAuth access tokens is not associated with any Ads accounts. Create a new account, or add the Google account to an existing Ads account" how can i fix this. Please help me ASAP

function createJwtAssertion() {
const jwtAssertion = jwt.sign({
iss: clientId, // Client ID
aud: 'https://oauth2.googleapis.com/token', // Token endpoint
exp: Math.floor(Date.now() / 1000) + 3600, // Expiration time (1 hour from now)
}, clientSecret, { algorithm: 'RS256' }); // Use your actual signing algorithm
return jwtAssertion;
}

const token = await axios.post('https://oauth2.googleapis.com/token', null, {
params: {
assertion: assertion,
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
},
});

Google Ads API Forum Advisor

unread,
Jan 3, 2024, 3:38:22 AM1/3/24
to mehul....@jambojar-tech.com, adwor...@googlegroups.com
Hi,

Thank you for getting back to us.

In order to investigate further, could you please provide more details regarding the issue you are encountering? Also, please provide us with the complete API logs and error screenshots.

Mehul Panchal

unread,
Jan 3, 2024, 4:10:06 AM1/3/24
to Google Ads API Forum Advisor, adwor...@googlegroups.com
hi Google

here is my rest of code where i get error

const query = 'SELECT campaign.id, campaign.name FROM campaign';
// const token = await getAccessToken();
const assertion = createJwtAssertion();
const token = await axios.post('https://oauth2.googleapis.com/token', null, {
params: {
assertion: assertion,
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
},
});
const headers = {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token.data.access_token}`,
'developer-token': 'Develper-token',
};



Error

{
  error: {
    code: 401,
    message: 'Request is missing required authentication credential. 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',
    details: [ [Object] ]
  }
} {
  '@type': 'type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure',
  errors: [
    {
      errorCode: [Object],
      message: 'The Google account (@gmail.com user) that generated the OAuth access tokens is not associated with any Ads accounts. Create a new account, or add the Google account to an existing Ads account.'
    }
  ],
  requestId: 'BLp9n91botsBIO1_WrZc6w'

Google Ads API Forum Advisor

unread,
Jan 3, 2024, 6:14:33 AM1/3/24
to mehul....@jambojar-tech.com, adwor...@googlegroups.com
Hi,

Thank you for getting back to us.

By reviewing your query, I understand that you are getting the error "UNAUTHENTICATED". Can you confirm if you have followed all the connectivity steps? For your reference, you may check on the Ensuring connectivity guide. 

If the issue still persists, kindly provide us with the updated complete API logs (request and response with request-id and request header) generated at your end to better assist you on this request. 

If you are using a client library and haven't enabled the logging yet, I would request you to enable logging for the specific client library that you are using. You can refer to the guides Java.NetPHPPythonRuby or Perl to enable logging at your end. For REST interface requests, you can enable logging via the curl command by using the -i flag.

You can send the details via Reply privately to the author option, or direct private reply to this email.
Message has been deleted
Message has been deleted

Google Ads API Forum Advisor

unread,
Jan 4, 2024, 3:03:56 AM1/4/24
to mehul....@jambojar-tech.com, adwor...@googlegroups.com
Hi,

Thank you for providing the additional information.

Upon checking the logs you have provided to us, I understand that you are encountering the error "NOT_ADS_USER".

The "NOT_ADS_USER" error means that the Google account used to generate the access token is not associated with any Google Ads account. The common cause for this issue is that the login information provided corresponds to a Google account that does not have Google Ads enabled. In order to handle this issue make sure to sign in with a valid Google Ads account (typically your manager account) for the OAuth flow. You can also invite the Google account to access an existing Google Ads account by signing in to your manager account, selecting the customer or manager account in question, navigating to Tools and Settings > Access and security, then adding the Google account email address. You may refer to this documentation for more information regarding this error.

I hope this helps. You can get back to us if you still have any issues/concerns related to the Google Ads API.
Reply all
Reply to author
Forward
0 new messages