1
---
2
name: google-ads-api-quickstart
3
description: |
4
Guides developers through Google Ads API quickstart: credential setup, choosing from 6 client libraries/REST, configuring environments, and running a "retrieve campaigns" script. Troubleshoots common setup errors: USER_PERMISSION_DENIED, login_customer_id issues, and CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION (a Google Cloud project with Test access calling a production account).
5
6
Use this skill when:
7
- The user asks how to get started with the Google Ads API.
8
- The user needs to set up Google Ads API access in a Google Cloud project or OAuth credentials.
9
- The user wants to write a quickstart/example script for Google Ads.
10
- The user encounters errors like USER_PERMISSION_DENIED, CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION, or the legacy DEVELOPER_TOKEN_NOT_APPROVED.
11
compatibility: "Outbound HTTPS connectivity required to access the Google Ads API and documentation. Note: If network access is restricted, the agent will fall back to using the last-known stable versions cached within the skill resources."
12
metadata:
13
author: google-ads-api-team
14
version: "1.1.1"
15
category: GoogleAds
16
---
17
# Google Ads API Quickstart
18
This skill guides you from absolute zero to running your first successful request to retrieve campaigns.
19
20
## Supported Tracks
21
You can choose to use this skill with:
22
23
1. **Official Client Libraries:** Python, Java, .NET, PHP, Ruby, or Perl.
24
2. **Direct REST:** Raw HTTP REST requests.
25
26
---
27
28
## Crucial Requirement: Dynamic Version Resolution & Runtime Resolution
29
30
> [!IMPORTANT]
31
> To ensure the integration is secure, stable, and up-to-date, you must resolve all API and runtime versions dynamically. Do not rely on hardcoded defaults.
32
33
### Strict Constraints:
34
35
* **DO NOT Hardcode:** Never use hardcoded Google Ads API versions (e.g., `v24`) or language runtime versions (e.g., `Python 3.8+`, `Java 11+`) in generated code or environment setup instructions, unless the user explicitly requests a specific version.
36
* **MANDATORY Dynamic Resolution:** You must dynamically resolve the latest stable versions *at the start of execution* before generating any code or configuration, using the procedures detailed below.
37
38
### A. Dynamic API Version Resolution
39
To ensure the integration is secure, stable, and up-to-date, you **MUST** resolve the absolute newest stable major version of the Google Ads API dynamically.
40
41
#### Execution Steps:
42
43
1. **Pre-Flight Version Resolution:** Use your web search or URL-reading tools to inspect the latest entry in the [Google Ads API Release Notes](https://developers.google.com/google-ads/api/docs/release-notes.md.txt) or the highest versioned directory in the [Googleapis Github Repository](https://github.com/googleapis/googleapis/tree/master/google/ads/googleads) to resolve `RESOLVED_API_VERSION` (e.g., `v24`). If using Java, you **MUST** also resolve the latest stable release version of the Google Ads Java Client Library (referred to as `RESOLVED_LIBRARY_VERSION`, e.g., `34.0.0`).
44
45
2. **Mandatory Response Anchor:** You **MUST** output the following confirmation block as the **very first line** of your response to the user. Do not output any greeting, pleasantries, or introductory text before this block.
46
47
```text
48
[SYSTEM: Using Google Ads API version: RESOLVED_API_VERSION (Resolved from release notes)]
49
```
50
51
3. **Strict Placeholder Mapping Table:** You **MUST** perform on-the-fly search-and-replace on all code templates and reference files using the mapping table below. Do not leave raw placeholders in the final output.
52
53
| Target Language / Tech | Placeholder in Template | Replacement Pattern | Example (Assuming API `v24`) |
54
| :--- | :--- | :--- | :--- |
55
| **Java** (Maven/Gradle) | `LATEST_LIBRARY_VERSION` | Search & substitute the latest Maven release version of the library. | `34.0.0` |
56
| **Java** (Imports) | `vXX` | Replace with **lower-case** API version. | `com.google.ads.googleads.v24` |
57
| **.NET / C#** (Namespaces) | `VXX` | Replace with **title-case** API version. | `Google.Ads.GoogleAds.V24` |
58
| **PHP** (Namespaces) | `VXX` | Replace with **title-case** API version. | `Google\Ads\GoogleAds\V24` |
59
| **REST** (Endpoint URL) | `vXX` | Replace with **lower-case** API version. | `https://googleads.googleapis.com/v24/...` |
60
61
> [!TIP]
62
> **Offline Fallback:** If the URLs are unreachable or the scrape fails, do not halt execution. Fall back to these last-known stable versions:
63
> * **Google Ads API Major Version (`RESOLVED_API_VERSION`):** `v26`
64
> * **Java Client Library Version (`RESOLVED_LIBRARY_VERSION`):** `48.0.0`
65
66
### B. Dynamic Language Runtime Version Resolution
67
To prevent the generated setup guides from becoming obsolete due to language deprecation cycles, you **MUST** resolve language requirements dynamically.
68
69
#### Execution Steps:
70
71
1. **Fetch Live Requirements:** Use your URL-reading tools to inspect the official [Google Ads Client Libraries - Supported Versions](https://developers.google.com/google-ads/api/docs/client-libs.md.txt#supported_api_versions) page.
72
73
2. **Extract Minimums:** Identify the minimum supported runtime version for the user's chosen language by scanning the Overview page or compatibility tables (e.g., looking for explicit requirements like Python 3.8+, Java 11+, .NET 6.0+, PHP 8.1+, Ruby 3.0+).
74
75
3. **Apply On-The-Fly:** Substitute all runtime placeholders (e.g., `<PYTHON_MIN_VERSION>`) in your generated setup guides with these resolved versions.
76
77
> [!TIP]
78
> **Offline Fallback:** If the URL is unreachable or the scrape fails, do not halt execution. Fall back to these last-known safe minimum versions:
79
> * **Python:** `3.9+`
80
> * **Java:** `11+`
81
> * **.NET:** `6.0+`
82
> * **PHP:** `8.1+`
83
> * **Ruby:** `3.0+`
84
> * **Perl:** `5.28.1+`
85
86
---
87
88
## Step 1: Obtain Google Ads API Credentials
89
90
Before installing libraries or making API calls, you need a Google Cloud
91
project with Google Ads API access and four authentication parameters.
92
93
> [!NOTE]
94
> **Developer tokens were sunset on September 9, 2026.** API access levels now
95
> belong to the Google Cloud project that owns your OAuth client (or service
96
> account). Do not send the user to the API Center in a Google Ads manager
97
> account to request a developer token; those requests are no longer processed.
98
> Existing `developer_token` values in configuration files are ignored by the
99
> API and can be removed.
100
101
### 1. Google Cloud Project with Google Ads API Access
102
103
* **Purpose:** Holds your API access level and quota. The project that owns your OAuth client ID (or service account) determines which accounts you can call and how many operations per day you get.
104
* **How to Obtain:**
105
1. Open the [Google Ads API Overview page](https://console.cloud.google.com/google/ads-apis/overview) in the Google Cloud Console and select (or create) a project.
106
2. Click **Enable**. Enabling the API grants **Test access**: up to 15,000 operations per day against Google Ads **test accounts** only.
107
3. To call **production** accounts, apply for **Explorer access** from the
108
same Overview page (review is automated in most cases; up to 2,880
109
operations per day). **Basic** and **Standard** access are applied for
110
from the same page and require brand verification for the project.
111
4. If your team already had a developer token, its access level was transferred to the Cloud projects that used it in the 90 days before the sunset. Check the Overview page, not the API Center.
112
113
> [!WARNING]
114
> **Test Access Restriction:** If your Cloud project only has Test access, you
115
> **MUST ONLY** target **Google Ads Test Accounts**. Calling a production
116
> account fails with `CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION` (API v25 and
117
> later) or `ACTION_NOT_PERMITTED` (v24 and earlier).
118
119
### 2. OAuth2 Client ID & Client Secret
120
121
* **Purpose:** Identifies your application to Google's OAuth 2.0 server and allows you to request user authorization.
122
* **How to Obtain:**
123
1. Open the [Google Cloud Console](https://console.cloud.google.com/).
124
2. Create a new project (or select an existing one).
125
3. Search for the **Google Ads API** in the API Library and click
126
**Enable** (skip if you already enabled it in Section 1). Use the
127
**same project** as in Section 1: the project that owns the OAuth client
128
determines your API access level.
129
4. Configure the **OAuth Consent Screen**:
130
* Select **External** user type.
131
* Set the Publishing Status to **Testing**.
132
* > [!IMPORTANT]
133
* > **Add Test Users:** You **MUST** add the email address of the Google account you use to log into Google Ads as a **Test User** in this step. Otherwise, you will be blocked during authorization.
134
5. Create the OAuth Client:
135
* Go to **APIs & Services 🡒 Credentials**.
136
* Click **Create Credentials 🡒 OAuth client ID**.
137
* Select **Desktop App** as the Application Type.
138
* Name the client and click **Create**.
139
6. **Download Secrets:** Click the download icon (JSON) next to your newly created Client ID. Save this file locally as `client_secrets.json`.
140
141
### 3. OAuth2 Refresh Token
142
143
* **Purpose:** Allows your application to obtain new access tokens automatically without requiring manual user login every hour.
144
* **How to Obtain:**
145
You must run the Google Cloud (`gcloud`) CLI to generate your refresh token.
146
147
#### 1. Install and Verify gcloud CLI:
148
Ensure the [gcloud CLI](https://cloud.google.com/sdk/docs/install) is installed and available in your terminal.
149
150
#### 2. Execute the Login Flow:
151
Run the following command in your terminal, passing the path to the `client_secrets.json` file downloaded in the previous step:
152
153
```bash
154
gcloud auth application-default login \
155
--scopes=https://www.googleapis.com/auth/adwords,https://www.googleapis.com/auth/cloud-platform \
156
--client-id-file=client_secrets.json
157
```
158
159
#### 3. Authorize in Browser:
160
1. The command will open a Google Account login window in your browser.
161
2. Sign in using the **Test User** email registered in your OAuth Consent Screen setup.
162
3. If your app is unverified, click **Advanced** and continue to the project. Click **Continue** to grant permissions.
163
164
#### 4. Retrieve Your Refresh Token:
165
Once successful, `gcloud` will output a message indicating where the credentials were saved (typically `~/.config/gcloud/application_default_credentials.json`). Open that file to copy your `refresh_token`.
166
167
### 4. Client Customer ID
168
169
* **Purpose:** The 10-digit ID of the specific Google Ads account you want to query or make changes to.
170
* **Format:** Must be 10 digits with **no hyphens** (e.g., `1234567890`, NOT `123-456-7890`).
171
* **How to Find It:** Log in to the Google Ads UI; the ID is displayed in the top-right corner next to your user icon.
172
173
> [!IMPORTANT]
174
> **Test Account Requirement:** If your Google Cloud project only has Test
175
> access, this **MUST** be the Customer ID of a **Test Account**. Test accounts
176
> have a red "Test account" banner in the top right of the UI.
177
178
---
179
180
### 5. Login Customer ID
181
182
* **What it is:** The 10-digit Customer ID of the Google Ads Manager Account that owns or manages the target client account.
183
* **Format:** Must be 10 digits with **no hyphens** (e.g., `9876543210`).
184
* **When to Use:** This is **mandatory** if the OAuth user belongs to a Manager Account, but you are querying a child/client account (Client Customer ID).
185
186
> [!CAUTION]
187
> **Preventing `USER_PERMISSION_DENIED`:**
188
> If you are accessing a client account through a Manager Account hierarchy, you **MUST** set this parameter.
189
> * `login_customer_id` = The **Manager** Account ID.
190
> * `client_customer_id` = The **Child/Client** Account ID.
191
> Leaving `login_customer_id` blank in a manager-client hierarchy is the #1 cause of permission errors.
192
193
---
194
195
## Step 2: Choose Your Integration Strategy
196
197
Developers can connect to the Google Ads API using either the official high-level client libraries or direct HTTPS REST requests.
198
199
### Path A: Official Client Libraries (Recommended)
200
201
> [!IMPORTANT]
202
> **Mandatory Agent Directive:** Once the user selects their language, you **MUST**:
203
> 1. Use the `view_file` tool to lazy-load the corresponding reference file listed below.
204
> 2. Apply the **Dynamic Version Resolution** (Section B) to dynamically replace all `vXX`/`VXX` placeholders and library versions *before* generating code.
205
206
#### Python
207
If you need to set up the Google Ads API environment for Python, do not guess the configuration.
208
Instead, read the detailed setup guide:
209
210
* [Google Ads API Python Setup Reference](references/python.md)
211
*(Package: `google-ads`)*
212
213
#### Java
214
If you need to set up the Google Ads API environment for Java, do not guess the configuration.
215
Instead, read the detailed setup guide:
216
217
* [Google Ads API Java Setup Reference](references/java.md)
218
*(Artifact: `com.google.api-ads:google-ads`)*
219
220
#### .NET / C#
221
If you need to set up the Google Ads API environment for .NET/C#, do not guess the configuration.
222
Instead, read the detailed setup guide:
223
224
* [Google Ads API .NET Setup Reference](references/dotnet.md)
225
*(Package: `Google.Ads.GoogleAds`)*
226
227
#### PHP
228
If you need to set up the Google Ads API environment for PHP, do not guess the configuration.
229
Instead, read the detailed setup guide:
230
231
* [Google Ads API PHP Setup Reference](references/php.md)
232
*(Package: `googleads/google-ads-php`)*
233
234
#### Ruby
235
If you need to set up the Google Ads API environment for Ruby, do not guess the configuration.
236
Instead, read the detailed setup guide:
237
238
* [Google Ads API Ruby Setup Reference](references/ruby.md)
239
*(Gem: `google-ads-googleads`)*
240
241
#### Perl
242
If you need to set up the Google Ads API environment for Perl, do not guess the configuration.
243
Instead, read the detailed setup guide:
244
245
* [Google Ads API Perl Setup Reference](references/perl.md)
246
*(Package: `Google::Ads::GoogleAds::Client`)*
247
248
### Path B: Direct HTTP REST (No Library Overhead)
249
250
Use this path if the user's environment does not support the official client libraries (e.g., lightweight serverless functions, custom language stacks, or restricted runtimes).
251
252
> [!IMPORTANT]
253
> **Mandatory Agent Directive:** If the user chooses the REST path, you **MUST**:
254
> 1. Use the `view_file` tool to lazy-load the REST reference file below.
255
> 2. Apply **Dynamic Version Resolution** (Section B) to replace all `vXX` placeholders in the endpoint URLs (e.g., resolving `vXX` to `v24` in `https://googleads.googleapis.com/v24/...`).
256
257
#### REST (HTTP)
258
If you need to set up the Google Ads API environment for REST (HTTP), do not guess the configuration.
259
Instead, read the detailed setup guide:
260
261
* [Google Ads API REST Setup Reference](references/rest.md)
262
*(Protocol: Raw HTTP POST JSON)*
263
264
---
265
266
## Cross-Referencing: AI-Assistant & MCP Connection
267
268
> [!TIP]
269
> **AI Assistant / MCP Integration Handoff:**
270
> If the goal is to connect an **AI Assistant** (such as Gemini, Cursor, or Claude Code) to query Google Ads via natural language:
271
> 1. **DO NOT** write custom scripts or client library code.
272
> 2. **STOP** executing this skill.
273
> 3. **Transition Immediately** to the **`google-ads-api-mcp-setup`** skill to install and configure the official Google Ads Model Context Protocol (MCP) Server.
274
275
---
276
277
## Step 4: Troubleshooting Common Errors
278
279
> [!IMPORTANT]
280
> **Static Diagnostics Constraint:** When troubleshooting, you **MUST NOT** execute bash commands, run local test scripts, or attempt to reproduce the error in the workspace. Rely entirely on static code analysis, configuration review, and the diagnostic guides below to prevent endless, failing execution loops.
281
282
### 1. Error: `USER_PERMISSION_DENIED`
283
284
* **Symptom:** You receive a `USER_PERMISSION_DENIED` error when executing API requests (e.g., retrieving campaigns).
285
* **Likely Cause:** The authenticating OAuth2 user has access to the target client account *indirectly* through a **Manager Account**, but the request header is missing the Manager Account's ID.
286
287
#### Required Agent Response Checklist:
288
When helping a user with this error, your response **MUST** include:
289
290
1. [ ] **Explain the Hierarchy:** Explain that the authenticating user likely belongs to a Manager Account that sits above the target client account.
291
2. [ ] **Provide the Fix:** Instruct the user to add their 10-digit Manager Account ID as the `login_customer_id` in their configuration file.
292
3. [ ] **Explain the Routing Logic:** Explain that `login_customer_id` tells the API to route the OAuth credentials through the manager account to validate access to the child account.
293
4. [ ] **Provide the Configuration Template:** Show the exact YAML configuration block below.
294
295
> [!CAUTION]
296
> **Security Guardrail:** Under no circumstances should you suggest exposing
297
> raw passwords, creating additional Google Cloud projects to avoid
298
> access-level review, or widening OAuth scopes beyond the standard `adwords`
299
> scope to bypass this error.
300
301
#### Configuration Fix Example (`google-ads.yaml`):
302
303
```yaml
304
client_id: INSERT_OAUTH2_CLIENT_ID_HERE
305
client_secret: INSERT_OAUTH2_CLIENT_SECRET_HERE
306
refresh_token: INSERT_OAUTH2_REFRESH_TOKEN_HERE
307
308
# Add your 10-digit Manager Account ID here to resolve USER_PERMISSION_DENIED:
309
login_customer_id: INSERT_LOGIN_CUSTOMER_ID_HERE
310
```
311
312
### 2. Error: `CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION`
313
314
* **Symptom:** The script fails with `AuthorizationError.CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION` (API v25 and later) or `AuthorizationError.ACTION_NOT_PERMITTED` (v24 and earlier).
315
* **Likely Cause:** The Google Cloud project that owns your OAuth client has only **Test access**, and you are targeting a live production Google Ads account.
316
* **Legacy Variant:** Code that still sends a developer token may report
317
`DEVELOPER_TOKEN_NOT_APPROVED`. Developer tokens were sunset on
318
September 9, 2026. The fix is the same (the access level of the Cloud
319
project), plus upgrading the client library to a version that no longer
320
requires the token.
321
322
#### Required Agent Response Checklist:
323
When helping a user with this error, your response **MUST** include:
324
325
1. [ ] **Explain the Test Access Restriction:** Explain that a Cloud project with Test access is fully functional but **restricted to Google Ads Test Accounts only**.
326
2. [ ] **Define Production Access Levels:** You **MUST** explicitly list all
327
three access levels by name: state that targeting live production accounts
328
requires the Cloud project to hold **Explorer Access**, **Basic Access**,
329
or **Standard Access**, applied for on the
330
[Google Ads API Overview page](https://console.cloud.google.com/google/ads-apis/overview)
331
in the Google Cloud Console. Do not condense or paraphrase this to "at
332
least Basic Access".
333
3. [ ] **Check the Right Project:** Remind the user that the access level is
334
read from the project that owns the OAuth client ID (user authentication)
335
or the service account (service account authentication), not from the
336
project currently selected in `gcloud`.
337
4. [ ] **Provide Sandbox Setup Steps:** Guide the user on how to set up a sandbox environment:
338
* Create a **Test Manager Account** (available with Test access).
339
* Create **Test Client Accounts** under that Test Manager.
340
* Use the Test Client Customer ID in their configuration.
341
5. [ ] **Provide Links to the Guides:** Point the user to the official [Google Ads API Test Accounts Guide](https://developers.google.com/google-ads/api/docs/best-practices/test-accounts.md.txt) and the [API access levels guide](https://developers.google.com/google-ads/api/docs/api-policy/access-levels.md.txt).
342
343
> [!CAUTION]
344
> **Security & Integrity Guardrail:** You **MUST NOT** advise the developer to
345
> modify the client library source code, bypass access-level checks, or use
346
> third-party "cracked" wrappers to bypass this error. The restriction is
347
> enforced server-side by Google, and client-side modifications will not work.
348
349