Search code examples
javascriptgoogle-oauthgoogle-ads-api

AdWords Scope: gapi.client.adwords missing after authenticating with OAuth flow. Cannot find path variable to pass to gapi.client.request()


I followed this guide to create a web app flow for authenticating users with Google.

Despite listing https://www.googleapis.com/auth/adwords in the scope parameter, I don't get a gapi.client.adwords or anything like that once the authentication is complete. I am unable to retrieve any information about the user's MCC/AdWords/Ad Manager accounts.

I've tried using gapi.client.request() but I can't seem to find the arguments that I should pass for access to the AdWords API.

I'm trying to do something like this:

let __req = gapi.client.request({
  method: "GET",
  path: "/adwords/v?/???",
  params: { fields: "???" }
});

__req.execute(function(response) {
  console.log(response);
});

... or like this:

console.log(gapi.client.adwords)

but I can't figure out what I need to pass to gapi.client.request and gapi.client.adwords doesn't exist.

Is it possible that I'm not passing a discoveryDoc or something like that? Where is the discoveryDoc for AdWords?

scope:
  "https://www.googleapis.com/auth/adwords",
discoveryDocs: ["???"]

Use Case: I'm trying to get a list of MCC/AdWords/Ad Manager accounts (specifically their ID's and names) that are associated with (or owned by) the authenticated user.

Thanks in advance!


Solution

  • The Google Ads / Adwords API is pretty different from many other Google interfaces in that it isn't open to the general public and can't be accessed with the "normal" API client libraries.

    In order to interact with the Ads API (same goes for the older Adwords API) and access production accounts, you are required to present a valid developer token. To obtain one, you'll need to sign up for access as described here. Note that you'll get a developer token immediately, but you will only be able to access test accounts until your application has been verified.

    Once you have a developer token, it's recommended to use the official client libraries:

    Unfortunately neither API currently offers official JS client libraries.