google-ads-cli 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google_ads_cli-0.0.1.dist-info/METADATA +212 -0
- google_ads_cli-0.0.1.dist-info/RECORD +28 -0
- google_ads_cli-0.0.1.dist-info/WHEEL +4 -0
- google_ads_cli-0.0.1.dist-info/entry_points.txt +2 -0
- google_ads_cli-0.0.1.dist-info/licenses/LICENSE +201 -0
- googleadscli/__init__.py +1 -0
- googleadscli/cli.py +81 -0
- googleadscli/client_factory.py +24 -0
- googleadscli/commands/__init__.py +0 -0
- googleadscli/commands/_common.py +26 -0
- googleadscli/commands/accounts.py +49 -0
- googleadscli/commands/auth.py +150 -0
- googleadscli/commands/call.py +76 -0
- googleadscli/commands/fields.py +94 -0
- googleadscli/commands/highlevel/__init__.py +18 -0
- googleadscli/commands/highlevel/ad.py +49 -0
- googleadscli/commands/highlevel/ad_group.py +46 -0
- googleadscli/commands/highlevel/budget.py +46 -0
- googleadscli/commands/highlevel/campaign.py +106 -0
- googleadscli/commands/highlevel/keyword.py +46 -0
- googleadscli/commands/mutate.py +53 -0
- googleadscli/commands/query.py +35 -0
- googleadscli/config.py +128 -0
- googleadscli/errors.py +81 -0
- googleadscli/formatting.py +55 -0
- googleadscli/gaql.py +37 -0
- googleadscli/proto_bridge.py +308 -0
- googleadscli/utils.py +22 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: google-ads-cli
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Vollumfaengliche Kommandozeilen-CLI fuer die Google Ads API (v25), fuer die Nutzung durch KI-Agenten
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Requires-Dist: google-ads>=32.0.0
|
|
9
|
+
Requires-Dist: google-auth-oauthlib>=1.2
|
|
10
|
+
Requires-Dist: pyyaml>=6.0
|
|
11
|
+
Requires-Dist: rich>=13.0
|
|
12
|
+
Requires-Dist: typer>=0.12
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest-mock>=3.14; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# google-ads-cli (`gads`)
|
|
20
|
+
|
|
21
|
+
Vollumfängliche Kommandozeilen-CLI für die Google Ads API (aktuell v25),
|
|
22
|
+
gebaut für die Steuerung durch KI-Agenten: nicht-interaktiv, mit JSON als
|
|
23
|
+
Standard-Ein-/Ausgabeformat und klaren Exit-Codes.
|
|
24
|
+
|
|
25
|
+
## Warum keine per-Ressource-Subcommands?
|
|
26
|
+
|
|
27
|
+
Die Google Ads API hat >100 Services und hunderte Ressourcen. Statt für jede
|
|
28
|
+
einzelne Ressource eigenen Code zu schreiben, nutzt `gads` die durchgängige
|
|
29
|
+
GAPIC-Namenskonvention der API per Reflection aus. Drei generische Befehle
|
|
30
|
+
decken dadurch **die gesamte API** ab:
|
|
31
|
+
|
|
32
|
+
- `gads query` — beliebige GAQL-Abfragen (Reporting/Lesen)
|
|
33
|
+
- `gads mutate <resource>` — generisches create/update/remove für jede
|
|
34
|
+
mutierbare Ressource (`campaign`, `ad_group`, `ad_group_criterion`, ...)
|
|
35
|
+
- `gads call <Service> <Methode>` — Fallback für alles andere (BatchJobService,
|
|
36
|
+
ConversionUploadService, OfflineUserDataJobService, KeywordPlanService,
|
|
37
|
+
GoogleAdsFieldService, CustomerService, Long-Running-Operations, ...)
|
|
38
|
+
|
|
39
|
+
Dazu kommt eine kleine Zahl komfortabler High-Level-Befehle unter `gads hl`
|
|
40
|
+
(Kampagne/Budget/Ad Group/Keyword/Anzeige anlegen) als dünne Wrapper — reine
|
|
41
|
+
Ergonomie, keine zusätzliche Abdeckung nötig.
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
47
|
+
pip install -e ".[dev]"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Einrichtung (einmalig, danach vollständig nicht-interaktiv)
|
|
51
|
+
|
|
52
|
+
Zwei Auth-Methoden werden unterstützt:
|
|
53
|
+
|
|
54
|
+
### Option A: Service Account (Google Cloud Console)
|
|
55
|
+
|
|
56
|
+
Empfohlen, wenn der API-Zugriff über ein GCP-Projekt/Service-Account verwaltet
|
|
57
|
+
wird (kein interaktiver Consent-Flow nötig):
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
gads auth use-service-account \
|
|
61
|
+
--json-key-file-path /pfad/zur/service-account.json \
|
|
62
|
+
--login-customer-id <MCC_CID> # optional, falls ueber ein MCC zugegriffen wird
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Voraussetzung: die `client_email` aus der Schlüsseldatei muss auf dem
|
|
66
|
+
Google-Ads-Konto (oder MCC) unter **Tools & Einstellungen > Zugriff und
|
|
67
|
+
Sicherheit > Nutzer** als Nutzer hinterlegt sein. Ein klassischer Developer
|
|
68
|
+
Token ist dabei nicht zwingend erforderlich (Google Ads "Cloud-managed access"
|
|
69
|
+
für Cloud-Organization-verknüpfte Projekte) — optional per `--developer-token`
|
|
70
|
+
setzbar, falls vorhanden. Domain-Wide-Delegation (Impersonation eines
|
|
71
|
+
Workspace-Nutzers) ist nur nötig, wenn die client_email nicht direkt als
|
|
72
|
+
Kontonutzer hinterlegt wurde; dafür `--impersonated-email` setzen.
|
|
73
|
+
|
|
74
|
+
Die Schlüsseldatei selbst sollte **außerhalb** des Repos liegen (z.B. unter
|
|
75
|
+
`~/.config/google-ads-cli/`) — sie enthält einen privaten Schlüssel und darf
|
|
76
|
+
nie committet werden.
|
|
77
|
+
|
|
78
|
+
### Option B: OAuth Installed-App-Flow
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
gads auth login \
|
|
82
|
+
--client-id <OAUTH_CLIENT_ID> \
|
|
83
|
+
--client-secret <OAUTH_CLIENT_SECRET> \
|
|
84
|
+
--developer-token <DEVELOPER_TOKEN> \
|
|
85
|
+
--login-customer-id <MCC_CID> # optional
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Beide Befehle speichern die Konfiguration unter
|
|
89
|
+
`~/.config/google-ads-cli/google-ads.yaml` (Dateirechte 600). Danach laufen
|
|
90
|
+
alle weiteren Befehle vollständig nicht-interaktiv.
|
|
91
|
+
|
|
92
|
+
Für Container/CI ganz ohne Datei: alle Felder sind per Env-Var überschreibbar
|
|
93
|
+
(`GOOGLE_ADS_DEVELOPER_TOKEN`, `GOOGLE_ADS_CLIENT_ID`, `GOOGLE_ADS_CLIENT_SECRET`,
|
|
94
|
+
`GOOGLE_ADS_REFRESH_TOKEN`, `GOOGLE_ADS_JSON_KEY_FILE_PATH`,
|
|
95
|
+
`GOOGLE_ADS_IMPERSONATED_EMAIL`, `GOOGLE_ADS_USE_APPLICATION_DEFAULT_CREDENTIALS`,
|
|
96
|
+
`GOOGLE_ADS_LOGIN_CUSTOMER_ID`).
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
gads auth status # prueft die Config gegen die echte API
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Nutzung
|
|
103
|
+
|
|
104
|
+
**GAQL-Abfrage (Reporting):**
|
|
105
|
+
```bash
|
|
106
|
+
gads query -c 1234567890 -q "
|
|
107
|
+
SELECT campaign.id, campaign.name, metrics.clicks
|
|
108
|
+
FROM campaign
|
|
109
|
+
WHERE segments.date DURING LAST_7_DAYS"
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Kampagne erstellen (generischer `mutate`-Befehl):**
|
|
113
|
+
```bash
|
|
114
|
+
gads mutate campaign -c 1234567890 -o '[
|
|
115
|
+
{"create": {"name": "Meine Kampagne", "status": "PAUSED",
|
|
116
|
+
"advertising_channel_type": "SEARCH",
|
|
117
|
+
"campaign_budget": "customers/1234567890/campaignBudgets/111"}}
|
|
118
|
+
]'
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Dieselbe Operation zuerst nur validieren:**
|
|
122
|
+
```bash
|
|
123
|
+
gads mutate campaign -c 1234567890 --dry-run -o '[...]'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Kampagne pausieren (update mit automatischer Field-Mask):**
|
|
127
|
+
```bash
|
|
128
|
+
gads mutate campaign -c 1234567890 -o '[
|
|
129
|
+
{"update": {"resource_name": "customers/1234567890/campaigns/999", "status": "PAUSED"}}
|
|
130
|
+
]'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**Generischer Fallback für jede andere API-Methode:**
|
|
134
|
+
```bash
|
|
135
|
+
gads list-services
|
|
136
|
+
gads list-methods BatchJobService
|
|
137
|
+
gads call BatchJobService mutate -c 1234567890 -r '{"customer_id": "1234567890", "mutate_operation": [...]}'
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Komfortbefehle:**
|
|
141
|
+
```bash
|
|
142
|
+
gads hl budget create -c 1234567890 --name "Budget A" --amount-micros 5000000
|
|
143
|
+
gads hl campaign create -c 1234567890 --name "Kampagne A" --budget customers/1234567890/campaignBudgets/111
|
|
144
|
+
gads hl keyword add -c 1234567890 --ad-group customers/.../adGroups/222 --text "schuhe kaufen" --match-type BROAD
|
|
145
|
+
gads accounts list-hierarchy -c <MCC_CID>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Feld-Metadaten nachschlagen** (welche Felder bietet eine Ressource? kein
|
|
149
|
+
Kundenkonto nötig — Wrapper um `GoogleAdsFieldService`, den globalen
|
|
150
|
+
Feld-Katalog der API):
|
|
151
|
+
```bash
|
|
152
|
+
gads fields list ad_group # alle Felder von ad_group
|
|
153
|
+
gads fields list ad_group --category METRIC # nur Metriken
|
|
154
|
+
gads fields list campaign.network_settings # Felder einer Unter-Message
|
|
155
|
+
gads fields show ad_group.status # volle Metadaten inkl. enum_values, selectable_with
|
|
156
|
+
```
|
|
157
|
+
Zeigt `selectable`/`filterable`/`sortable`/`enum_values`/`data_type` und (bei
|
|
158
|
+
`show`) `selectable_with` (mit welchen anderen Ressourcen/Segmenten/Metriken
|
|
159
|
+
sich das Feld in einer GAQL-Abfrage kombinieren lässt). Das sagt nur, was per
|
|
160
|
+
GAQL *lesbar* ist — nicht, was per `mutate` *schreibbar* oder mit welchem
|
|
161
|
+
`advertising_channel_type` kompatibel ist. Das lässt sich nur durch Lesen des
|
|
162
|
+
Resource-Protos oder durch `--dry-run`-Ausprobieren herausfinden (siehe
|
|
163
|
+
"Wie ich das selbst mache" unten).
|
|
164
|
+
|
|
165
|
+
## Agenten-Vertrag
|
|
166
|
+
|
|
167
|
+
- Ausgabe: reines JSON auf stdout (Standard; `--format table`/`--format csv`
|
|
168
|
+
für Menschen). Logs/Fehler gehen nach stderr.
|
|
169
|
+
- Exit-Codes: `0` Erfolg, `1` CLI-/Validierungsfehler, `2` Google-Ads-API-Fehler
|
|
170
|
+
(strukturiertes JSON mit `error_code`, `message`, `field_path`), `70`
|
|
171
|
+
unerwarteter interner Fehler.
|
|
172
|
+
- Mutate-Befehle laufen standardmäßig sofort durch (kein Bestätigungszwang,
|
|
173
|
+
wichtig für autonome Agenten); `--dry-run` nutzt `validate_only` der API.
|
|
174
|
+
|
|
175
|
+
## Feld-/Schema-Recherche jenseits von `gads fields`
|
|
176
|
+
|
|
177
|
+
`gads fields` beantwortet "was ist per GAQL selectable/filterable?". Für
|
|
178
|
+
"was ist bei `mutate` überhaupt als Feld vorhanden, und welchen Typ/Enum-Wert
|
|
179
|
+
erwartet es?" hilft zusätzlich eine kurze Python-Introspektion gegen die
|
|
180
|
+
lokal installierten, generierten Klassen der `google-ads`-Bibliothek (rein
|
|
181
|
+
lokal, kein API-Call, keine Zugangsdaten nötig):
|
|
182
|
+
|
|
183
|
+
```python
|
|
184
|
+
from google.ads.googleads.v25.resources.types.ad_group import AdGroup
|
|
185
|
+
for f in AdGroup.pb().DESCRIPTOR.fields:
|
|
186
|
+
print(f.name, [v.name for v in f.enum_type.values] if f.enum_type else f.type)
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
Für die dritte Frage — "ist dieses Feld bei `mutate` für einen bestimmten
|
|
190
|
+
`advertising_channel_type` tatsächlich beschreibbar?" — gibt es keine
|
|
191
|
+
Metadatenquelle; das zeigt nur ein echter `--dry-run`-Aufruf (siehe die
|
|
192
|
+
Fehlercodes `OPERATION_NOT_PERMITTED_FOR_CONTEXT`, `IMMUTABLE_FIELD`,
|
|
193
|
+
`SETTING_TYPE_IS_NOT_COMPATIBLE_WITH_CAMPAIGN` in `errors.py`).
|
|
194
|
+
|
|
195
|
+
## Tests
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
pytest
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Alle Tests laufen ohne echte Google-Ads-Zugangsdaten (Reflection gegen die
|
|
202
|
+
echten generierten Protobuf-Klassen, RPC-Aufrufe selbst werden mit
|
|
203
|
+
`unittest.mock.patch.object(..., autospec=True)` gemockt).
|
|
204
|
+
|
|
205
|
+
## Status
|
|
206
|
+
|
|
207
|
+
Kernbefehle (`query`, `mutate`, `call`, `auth`, `accounts`, `hl`) sind
|
|
208
|
+
implementiert, getestet und gegen ein echtes Google-Ads-Konto (Service-Account-
|
|
209
|
+
Auth, Cloud-managed Access ohne Developer Token) live verifiziert: `auth
|
|
210
|
+
status`, `query`, `accounts list-hierarchy`, `mutate --dry-run` (inkl.
|
|
211
|
+
mehrteiliger Validierungsfehler) und der generische `call`-Fallback
|
|
212
|
+
funktionieren wie erwartet.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
googleadscli/__init__.py,sha256=sXLh7g3KC4QCFxcZGBTpG2scR7hmmBsMjq6LqRptkRg,22
|
|
2
|
+
googleadscli/cli.py,sha256=61FHNAAZ557C7xkouULL9WKMFL7Bir_gz-0b9Qjis4I,3160
|
|
3
|
+
googleadscli/client_factory.py,sha256=htmNQHYcqSI9Y47fjKdlWQz76vYELrzpG0kIPgr96nM,794
|
|
4
|
+
googleadscli/config.py,sha256=ilkke39z3VDQ_sk15_QZHqCganPL1YgR-NFE8eez8fw,5391
|
|
5
|
+
googleadscli/errors.py,sha256=dlEayIxudJwXMA8WhWXyo3FsUIczT4vv5LTI2mMeYcI,2711
|
|
6
|
+
googleadscli/formatting.py,sha256=K1IYXkSBC3NpNjPNujdDriCH0g4Hjc1filPyu42vaXQ,1701
|
|
7
|
+
googleadscli/gaql.py,sha256=duH2sA2vPGjeU7oJlaREb7xAAM-YVVWetDxiiKlfO-o,1316
|
|
8
|
+
googleadscli/proto_bridge.py,sha256=NEg7SOf6g4oV1b7zM2Tl8H_ntT49_GkdJOn_-yn3HYo,10664
|
|
9
|
+
googleadscli/utils.py,sha256=CKyBAZW_xRmE-90r7x2ddpZSaCB1nvPRmQefJefduuc,695
|
|
10
|
+
googleadscli/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
googleadscli/commands/_common.py,sha256=auVk_-md-0gJRsOryP86_YtW2uOua1bEgMDCruved5Y,712
|
|
12
|
+
googleadscli/commands/accounts.py,sha256=-3QD3xFpIwFLIwmd1-w9-1rEFyVQULScC0CFDt-I_8o,1498
|
|
13
|
+
googleadscli/commands/auth.py,sha256=nJjeZ4Mu8bnHMDi7XaWIU2yyoFszMlQHZGsmjTOCwVk,5925
|
|
14
|
+
googleadscli/commands/call.py,sha256=p3N3lwwRsE7sTHP1n2kBFvTLNyY5PJ4COxAE82npt54,2970
|
|
15
|
+
googleadscli/commands/fields.py,sha256=wObAxpkb31QYJr8q3i2k8NiOlAawZqx1ha7Phf29JKs,3511
|
|
16
|
+
googleadscli/commands/mutate.py,sha256=gXJpfkjRAVjTsflVN0OFM0fbWh9D-8g-9sXG59fEYNY,1994
|
|
17
|
+
googleadscli/commands/query.py,sha256=4bMiV_Dvkk61w8TKr4YRbKCoC2bsS6CgclslDz4PRsw,1168
|
|
18
|
+
googleadscli/commands/highlevel/__init__.py,sha256=bGcvMgzVYCx8Bjvpt2zGSUBZrJ-DwEwnnag-zhfqZUI,652
|
|
19
|
+
googleadscli/commands/highlevel/ad.py,sha256=51FbUWuM3X6oGiQZHDlj_JXnHQaUWIiP02YwqXpEzng,1821
|
|
20
|
+
googleadscli/commands/highlevel/ad_group.py,sha256=sDMMK0-X3u1v2It9WffJ-MaG0DNS5ygLAj1ACi_jlY8,1496
|
|
21
|
+
googleadscli/commands/highlevel/budget.py,sha256=G2KqKo_hExcVYrdswprTfGApQWLMb3JTp2kUa0eM4pQ,1580
|
|
22
|
+
googleadscli/commands/highlevel/campaign.py,sha256=GA-VeLRl8lF2lDqNOo516gk1o-V0ClcQJI8aQGpaEps,3654
|
|
23
|
+
googleadscli/commands/highlevel/keyword.py,sha256=luOtYdoeHeW9BXLasdCSUVrrw66RslERv0BQ2ycAIso,1662
|
|
24
|
+
google_ads_cli-0.0.1.dist-info/METADATA,sha256=ujqBua5RlHRbNm6r4iwvvJIshrW0Ua4DuCUeYrAPjsk,8468
|
|
25
|
+
google_ads_cli-0.0.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
26
|
+
google_ads_cli-0.0.1.dist-info/entry_points.txt,sha256=5I7iv1LKMxC163FARU_bn13mOYTN_2G9g7eLZE7U13U,47
|
|
27
|
+
google_ads_cli-0.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
28
|
+
google_ads_cli-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
googleadscli/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.0.1"
|
googleadscli/cli.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Root Typer-App: globale Optionen, Fehlerbehandlung, Subcommand-Registrierung."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import typer
|
|
6
|
+
|
|
7
|
+
from googleadscli.commands import accounts, auth, call, fields, highlevel, mutate, query
|
|
8
|
+
|
|
9
|
+
app = typer.Typer(
|
|
10
|
+
no_args_is_help=True,
|
|
11
|
+
add_completion=False,
|
|
12
|
+
help="Vollumfaengliche CLI fuer die Google Ads API (v25) -- fuer KI-Agenten.",
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@app.callback()
|
|
17
|
+
def main_callback(
|
|
18
|
+
ctx: typer.Context,
|
|
19
|
+
config: str = typer.Option(
|
|
20
|
+
None, "--config", envvar="GOOGLE_ADS_CONFIGURATION_FILE_PATH", help="Pfad zur google-ads.yaml"
|
|
21
|
+
),
|
|
22
|
+
api_version: str = typer.Option("v25", "--api-version", help="Google Ads API Version"),
|
|
23
|
+
output_format: str = typer.Option("json", "--format", help="Ausgabeformat: json|table|csv"),
|
|
24
|
+
developer_token: str = typer.Option(None, "--developer-token", envvar="GOOGLE_ADS_DEVELOPER_TOKEN"),
|
|
25
|
+
client_id: str = typer.Option(None, "--client-id", envvar="GOOGLE_ADS_CLIENT_ID"),
|
|
26
|
+
client_secret: str = typer.Option(None, "--client-secret", envvar="GOOGLE_ADS_CLIENT_SECRET"),
|
|
27
|
+
refresh_token: str = typer.Option(None, "--refresh-token", envvar="GOOGLE_ADS_REFRESH_TOKEN"),
|
|
28
|
+
json_key_file_path: str = typer.Option(
|
|
29
|
+
None,
|
|
30
|
+
"--json-key-file-path",
|
|
31
|
+
envvar="GOOGLE_ADS_JSON_KEY_FILE_PATH",
|
|
32
|
+
help="Pfad zu einer Service-Account-JSON-Schluesseldatei (Alternative zum OAuth-Flow)",
|
|
33
|
+
),
|
|
34
|
+
impersonated_email: str = typer.Option(
|
|
35
|
+
None,
|
|
36
|
+
"--impersonated-email",
|
|
37
|
+
envvar="GOOGLE_ADS_IMPERSONATED_EMAIL",
|
|
38
|
+
help="Nur fuer Domain-Wide-Delegation: zu impersonierender Workspace-Nutzer",
|
|
39
|
+
),
|
|
40
|
+
use_adc: bool = typer.Option(
|
|
41
|
+
False,
|
|
42
|
+
"--use-adc",
|
|
43
|
+
envvar="GOOGLE_ADS_USE_APPLICATION_DEFAULT_CREDENTIALS",
|
|
44
|
+
help="Application Default Credentials verwenden statt expliziter Zugangsdaten",
|
|
45
|
+
),
|
|
46
|
+
login_customer_id: str = typer.Option(None, "--login-customer-id", envvar="GOOGLE_ADS_LOGIN_CUSTOMER_ID"),
|
|
47
|
+
debug: bool = typer.Option(False, "--debug", help="Vollstaendige Tracebacks statt strukturierter Fehler"),
|
|
48
|
+
) -> None:
|
|
49
|
+
ctx.obj = {
|
|
50
|
+
"config_path": config,
|
|
51
|
+
"version": api_version,
|
|
52
|
+
"format": output_format,
|
|
53
|
+
"debug": debug,
|
|
54
|
+
"cli_overrides": {
|
|
55
|
+
"developer_token": developer_token,
|
|
56
|
+
"client_id": client_id,
|
|
57
|
+
"client_secret": client_secret,
|
|
58
|
+
"refresh_token": refresh_token,
|
|
59
|
+
"json_key_file_path": json_key_file_path,
|
|
60
|
+
"impersonated_email": impersonated_email,
|
|
61
|
+
"use_application_default_credentials": use_adc or None,
|
|
62
|
+
"login_customer_id": login_customer_id,
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
app.add_typer(auth.app, name="auth", help="OAuth2-Einrichtung und Zugangspruefung")
|
|
68
|
+
app.add_typer(accounts.app, name="accounts", help="Kontohierarchie / CIDs unter einem MCC")
|
|
69
|
+
app.add_typer(highlevel.app, name="hl", help="Komfortbefehle fuer haeufige Workflows")
|
|
70
|
+
app.add_typer(fields.app, name="fields", help="Feld-Metadaten der API nachschlagen")
|
|
71
|
+
query.register(app)
|
|
72
|
+
mutate.register(app)
|
|
73
|
+
call.register(app)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def main() -> None:
|
|
77
|
+
app()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
main()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Aufbau des GoogleAdsClient aus der gemergten Konfiguration."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from google.ads.googleads.client import GoogleAdsClient
|
|
8
|
+
|
|
9
|
+
from googleadscli.config import ConfigError, load_merged_config
|
|
10
|
+
|
|
11
|
+
DEFAULT_API_VERSION = "v25"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_client(
|
|
15
|
+
*,
|
|
16
|
+
config_path: str | None = None,
|
|
17
|
+
cli_overrides: dict[str, Any] | None = None,
|
|
18
|
+
version: str = DEFAULT_API_VERSION,
|
|
19
|
+
) -> GoogleAdsClient:
|
|
20
|
+
merged = load_merged_config(config_path=config_path, cli_overrides=cli_overrides)
|
|
21
|
+
try:
|
|
22
|
+
return GoogleAdsClient.load_from_dict(merged, version=version)
|
|
23
|
+
except Exception as exc: # Konfigurationsfehler der Client Library selbst
|
|
24
|
+
raise ConfigError(f"Google Ads Client konnte nicht initialisiert werden: {exc}") from exc
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""Gemeinsame Hilfsfunktionen fuer Subcommands: Fehler-Guard, Client-Aufbau."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
|
|
10
|
+
from googleadscli import client_factory, errors
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_client(ctx: typer.Context):
|
|
14
|
+
obj = ctx.obj
|
|
15
|
+
return client_factory.build_client(
|
|
16
|
+
config_path=obj["config_path"],
|
|
17
|
+
cli_overrides=obj["cli_overrides"],
|
|
18
|
+
version=obj["version"],
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run_guarded(ctx: typer.Context, fn: Callable[[], Any]) -> Any:
|
|
23
|
+
try:
|
|
24
|
+
return fn()
|
|
25
|
+
except Exception as exc: # strukturierte Fehlerausgabe statt rohem Traceback
|
|
26
|
+
errors.handle_exception(exc, debug=ctx.obj.get("debug", False))
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""`gads accounts list-hierarchy` -- MCC-Kontohierarchie / CIDs auflisten.
|
|
2
|
+
|
|
3
|
+
Duenner Komfort-Wrapper: die Google Ads API liefert ueber die `customer_client`-
|
|
4
|
+
Ressource bereits die gesamte direkte und indirekte Kontohierarchie eines
|
|
5
|
+
Manager-Kontos (MCC) in einer einzigen GAQL-Abfrage.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
|
|
12
|
+
from googleadscli import formatting, gaql
|
|
13
|
+
from googleadscli.commands import _common
|
|
14
|
+
from googleadscli.utils import normalize_customer_id
|
|
15
|
+
|
|
16
|
+
app = typer.Typer(no_args_is_help=True, help="Kontohierarchie / CIDs unter einem MCC")
|
|
17
|
+
|
|
18
|
+
_HIERARCHY_QUERY = """
|
|
19
|
+
SELECT
|
|
20
|
+
customer_client.client_customer,
|
|
21
|
+
customer_client.level,
|
|
22
|
+
customer_client.manager,
|
|
23
|
+
customer_client.descriptive_name,
|
|
24
|
+
customer_client.currency_code,
|
|
25
|
+
customer_client.time_zone,
|
|
26
|
+
customer_client.status
|
|
27
|
+
FROM customer_client
|
|
28
|
+
WHERE customer_client.status = 'ENABLED'
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@app.command("list-hierarchy")
|
|
33
|
+
def list_hierarchy(
|
|
34
|
+
ctx: typer.Context,
|
|
35
|
+
customer_id: str = typer.Option(..., "--customer-id", "-c", help="CID des (Manager-)Kontos, ab dem gelistet wird"),
|
|
36
|
+
) -> None:
|
|
37
|
+
"""Listet alle direkten und indirekten Kunden-CIDs unter einem MCC-Konto."""
|
|
38
|
+
|
|
39
|
+
def _run() -> None:
|
|
40
|
+
client = _common.build_client(ctx)
|
|
41
|
+
rows = gaql.run_query(
|
|
42
|
+
client,
|
|
43
|
+
normalize_customer_id(customer_id),
|
|
44
|
+
_HIERARCHY_QUERY,
|
|
45
|
+
version=ctx.obj["version"],
|
|
46
|
+
)
|
|
47
|
+
formatting.render(rows, fmt=ctx.obj["format"])
|
|
48
|
+
|
|
49
|
+
_common.run_guarded(ctx, _run)
|