Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51468cb

Browse files
committed
Merge branch 'main' of https://github.com/googleads/google-ads-python into googleads-main
2 parents 0b9c9a8 + 2a1d606 commit 51468cb

File tree

2,525 files changed

+220033
-155591
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,525 files changed

+220033
-155591
lines changed

ChangeLog

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
* 14.1.0
2+
- Google Ads API v9_0 release
3+
- Update gRPC transport logic to replace "gapic" user-agent with "gccl"
4+
- Update examples to support v9 changes
5+
- Add new Performance Max examples
6+
advanced_operations/add_performance_max_campaign.py and
7+
shopping_ads/add_performance_max_retail_campaign.py
8+
9+
* 14.0.1
10+
- Pin protobuf to < 3.18.0
11+
- Add examples add_bidding_data_exclusion, add_bidding_seasonality_adjustment
12+
- Style updates for examples that use search_stream
13+
- Fix hardcoded URLs for media in various examples
14+
15+
* 14.0.0
16+
- New required configuration value to specify protobuf message types, see:
17+
https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages
18+
- Google Ads API v8_1 release.
19+
- Remove support for Google Ads API v6.
20+
121
* 13.0.0
222
- Bump the minimum Python version requirement to 3.7+
323
- Fix package name in base transport files

README.rst

+15-7
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ For Python 3.6 Users
3232
--------------------
3333
Version `12.0.0`_ of this library is the last version that is compatible with
3434
Python 3.6. It contains support for `v6`_, `v7`_, and `v8`_ of the Google Ads
35-
API. The newest API version, `v8`_, will be supported until the Spring of 2022.
36-
Given that the `EOL`_ for Python 3.6 is December 23, 2021, we encourage our
37-
users to upgrade to Python 3.7 or above as soon as possible to avoid issues.
38-
Users who cannot upgrade can continue to safely use version `12.0.0`_ until
39-
`v8`_ of the Google Ads API is deprecated. Please follow the
40-
`Google Ads Developer Blog`_ for announcements of the specific deprecation
41-
dates for the above API versions.
35+
API. The latest API version supported by version `12.0.0`_, `v8`_, will be
36+
supported until the Spring of 2022, so Python 3.6 users can access the Google
37+
Ads API until then. Given that the `EOL`_ for Python 3.6 is December 23, 2021,
38+
we encourage our users to upgrade to Python 3.7 or above as soon as possible to
39+
avoid issues. Please follow the `Google Ads Developer Blog`_ for announcements
40+
of the specific deprecation dates for the above API versions.
41+
42+
Protobuf Messages
43+
-----------------
44+
Version `14.0.0`_ of this library introduced the **required** `use_proto_plus`
45+
configuration option that specifies which type of protobuf message to use. For
46+
information on why this flag is important and what the differences are between
47+
the two message types, see the `Protobuf Messages`_ guide.
4248

4349
Miscellaneous
4450
-------------
@@ -67,8 +73,10 @@ Authors
6773
.. _Andrew Burke: https://github.com/AndrewMBurke
6874
.. _Laura Chevalier: https://github.com/laurachevalier4
6975
.. _12.0.0: https://pypi.org/project/google-ads/12.0.0/
76+
.. _14.0.0: https://pypi.org/project/google-ads/14.0.0/
7077
.. _v6: https://developers.google.com/google-ads/api/reference/rpc/v6/overview
7178
.. _v7: https://developers.google.com/google-ads/api/reference/rpc/v7/overview
7279
.. _v8: https://developers.google.com/google-ads/api/reference/rpc/v8/overview
7380
.. _EOL: https://endoflife.date/python
7481
.. _Google Ads Developer Blog: https://ads-developers.googleblog.com/
82+
.. _Protobuf Messages: https://developers.google.com/google-ads/api/docs/client-libs/python/protobuf-messages

examples/account_management/approve_merchant_center_link.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def _update_merchant_center_link_status(
125125
if __name__ == "__main__":
126126
# GoogleAdsClient will read the google-ads.yaml configuration file in the
127127
# home directory if none is specified.
128-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
128+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
129129

130130
parser = argparse.ArgumentParser(
131131
description=("Approves a Merchant Center link request.")

examples/account_management/create_customer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def main(client, manager_customer_id):
5858
if __name__ == "__main__":
5959
# GoogleAdsClient will read the google-ads.yaml configuration file in the
6060
# home directory if none is specified.
61-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
61+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
6262

6363
parser = argparse.ArgumentParser(
6464
description=("Creates a new client under the given manager.")

examples/account_management/get_account_hierarchy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _print_account_hierarchy(
179179
if __name__ == "__main__":
180180
# GoogleAdsClient will read the google-ads.yaml configuration file in the
181181
# home directory if none is specified.
182-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
182+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
183183

184184
parser = argparse.ArgumentParser(
185185
description="This example gets the account hierarchy of the specified "

examples/account_management/get_account_information.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def main(client, customer_id):
4242
if __name__ == "__main__":
4343
# GoogleAdsClient will read the google-ads.yaml configuration file in the
4444
# home directory if none is specified.
45-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
45+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
4646

4747
parser = argparse.ArgumentParser(
4848
description=(

examples/account_management/get_change_details.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def main(client, customer_id):
177177
if __name__ == "__main__":
178178
# GoogleAdsClient will read the google-ads.yaml configuration file in the
179179
# home directory if none is specified.
180-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
180+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
181181

182182
parser = argparse.ArgumentParser(
183183
description="This example gets specific details about the most recent "

examples/account_management/get_change_summary.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def main(client, customer_id):
8585
if __name__ == "__main__":
8686
# GoogleAdsClient will read a google-ads.yaml configuration file in the
8787
# home directory if none is specified.
88-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
88+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
8989

9090
parser = argparse.ArgumentParser(
9191
description=(

examples/account_management/get_pending_invitations.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def main(client, customer_id):
4444
FROM customer_user_access_invitation
4545
WHERE customer_user_access_invitation.invitation_status = PENDING"""
4646

47-
response = googleads_service.search_stream(
47+
stream = googleads_service.search_stream(
4848
customer_id=customer_id, query=query
4949
)
50-
for batch in response:
50+
for batch in stream:
5151
for row in batch.results:
5252
invite = row.customer_user_access_invitation
5353
print(
@@ -65,7 +65,7 @@ def main(client, customer_id):
6565
if __name__ == "__main__":
6666
# GoogleAdsClient will read the google-ads.yaml configuration file in the
6767
# home directory if none is specified.
68-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
68+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
6969

7070
parser = argparse.ArgumentParser(
7171
description=("Retrieves pending invitations for a customer account.")

examples/account_management/invite_user_with_access_role.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def main(client, customer_id, email_address, access_role):
5959
if __name__ == "__main__":
6060
# GoogleAdsClient will read the google-ads.yaml configuration file in the
6161
# home directory if none is specified.
62-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
62+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
6363

6464
parser = argparse.ArgumentParser(
6565
description=(

examples/account_management/link_manager_to_client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def main(client, customer_id, manager_customer_id):
9191
)
9292
)
9393

94-
manager_link.status = client.enums.ManagerLinkStatusEnum.PENDING
94+
manager_link.status = client.enums.ManagerLinkStatusEnum.ACTIVE
9595
client.copy_from(
9696
manager_link_operation.update_mask,
9797
protobuf_helpers.field_mask(None, manager_link._pb),
@@ -110,7 +110,7 @@ def main(client, customer_id, manager_customer_id):
110110
if __name__ == "__main__":
111111
# GoogleAdsClient will read the google-ads.yaml configuration file in the
112112
# home directory if none is specified.
113-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
113+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
114114

115115
parser = argparse.ArgumentParser(
116116
description=(

examples/account_management/list_accessible_customers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main(client):
4444
if __name__ == "__main__":
4545
# GoogleAdsClient will read the google-ads.yaml configuration file in the
4646
# home directory if none is specified.
47-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
47+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
4848

4949
try:
5050
main(googleads_client)

examples/account_management/reject_merchant_center_link.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _remove_merchant_center_link(
129129
if __name__ == "__main__":
130130
# GoogleAdsClient will read the google-ads.yaml configuration file in the
131131
# home directory if none is specified.
132-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
132+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
133133

134134
parser = argparse.ArgumentParser(
135135
description=(

examples/account_management/update_user_access.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def _modify_user_access(client, customer_id, user_id, access_role):
137137
if __name__ == "__main__":
138138
# GoogleAdsClient will read the google-ads.yaml configuration file in the
139139
# home directory if none is specified.
140-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
140+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
141141

142142
parser = argparse.ArgumentParser(
143143
description="This code example updates the access role of a user, "

examples/advanced_operations/add_ad_customizer.py

+50-74
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,13 @@ def _create_add_customizer_feed(client, customer_id, feed_name):
104104

105105
feed_service = client.get_service("FeedService")
106106

107-
try:
108-
response = feed_service.mutate_feeds(
109-
customer_id=customer_id, operations=[feed_operation]
110-
)
111-
resource_name = response.results[0].resource_name
112-
print(f"Added feed with resource name {resource_name}")
113-
return resource_name
114-
except GoogleAdsException as ex:
115-
_handle_googleads_exception(ex)
116-
# [END add_ad_customizer]
107+
response = feed_service.mutate_feeds(
108+
customer_id=customer_id, operations=[feed_operation]
109+
)
110+
resource_name = response.results[0].resource_name
111+
print(f"Added feed with resource name {resource_name}")
112+
return resource_name
113+
# [END add_ad_customizer]
117114

118115

119116
# [START add_ad_customizer_1]
@@ -142,12 +139,9 @@ def _get_feed_attributes(client, customer_id, feed_resource_name):
142139
search_request.query = query
143140
search_request.page_size = 1
144141

145-
try:
146-
results = ga_service.search(request=search_request)
147-
feed = list(results)[0].feed
148-
print(f"Found the following attributes for feed with name {feed.name}")
149-
except GoogleAdsException as ex:
150-
_handle_googleads_exception(ex)
142+
results = ga_service.search(request=search_request)
143+
feed = list(results)[0].feed
144+
print(f"Found the following attributes for feed with name {feed.name}")
151145

152146
feed_details = {}
153147
for feed_attribute in feed.attributes:
@@ -206,17 +200,14 @@ def _create_ad_customizer_mapping(
206200

207201
feed_mapping_service = client.get_service("FeedMappingService")
208202

209-
try:
210-
response = feed_mapping_service.mutate_feed_mappings(
211-
customer_id=customer_id, operations=[feed_mapping_op]
203+
response = feed_mapping_service.mutate_feed_mappings(
204+
customer_id=customer_id, operations=[feed_mapping_op]
205+
)
206+
for result in response.results:
207+
print(
208+
"Created feed mapping with resource name "
209+
f"{result.resource_name}"
212210
)
213-
for result in response.results:
214-
print(
215-
"Created feed mapping with resource name "
216-
f"{result.resource_name}"
217-
)
218-
except GoogleAdsException as ex:
219-
_handle_googleads_exception(ex)
220211
# [END add_ad_customizer_2]
221212

222213

@@ -266,14 +257,11 @@ def _create_feed_items(
266257

267258
feed_item_service = client.get_service("FeedItemService")
268259

269-
try:
270-
response = feed_item_service.mutate_feed_items(
271-
customer_id=customer_id, operations=feed_item_operations
272-
)
273-
return [feed_item.resource_name for feed_item in response.results]
274-
except GoogleAdsException as ex:
275-
_handle_googleads_exception(ex)
276-
# [END add_ad_customizer_3]
260+
response = feed_item_service.mutate_feed_items(
261+
customer_id=customer_id, operations=feed_item_operations
262+
)
263+
return [feed_item.resource_name for feed_item in response.results]
264+
# [END add_ad_customizer_3]
277265

278266

279267
# [START add_ad_customizer_4]
@@ -353,17 +341,14 @@ def _create_feed_item_targets(
353341
customer_id, ad_group_id
354342
)
355343

356-
try:
357-
response = feed_item_target_service.mutate_feed_item_targets(
358-
customer_id=customer_id, operations=[feed_item_target_op]
359-
)
360-
print(
361-
"Added feed item target with resource name "
362-
f"{response.results[0].resource_name}"
363-
)
364-
except GoogleAdsException as ex:
365-
_handle_googleads_exception(ex)
366-
# [END add_ad_customizer_5]
344+
response = feed_item_target_service.mutate_feed_item_targets(
345+
customer_id=customer_id, operations=[feed_item_target_op]
346+
)
347+
print(
348+
"Added feed item target with resource name "
349+
f"{response.results[0].resource_name}"
350+
)
351+
# [END add_ad_customizer_5]
367352

368353

369354
# [START add_ad_customizer_6]
@@ -405,40 +390,19 @@ def _create_ads_with_customizations(
405390
)
406391
ad_group_ad_operations.append(ad_group_ad_operation)
407392

408-
try:
409-
response = ad_group_ad_service.mutate_ad_group_ads(
410-
customer_id=customer_id, operations=ad_group_ad_operations
411-
)
412-
print(f"Added {len(response.results)} ads:")
413-
for ad in response.results:
414-
print(f"Added an ad with resource name {ad.resource_name}")
415-
except GoogleAdsException as ex:
416-
_handle_googleads_exception(ex)
417-
# [END add_ad_customizer_6]
418-
419-
420-
def _handle_googleads_exception(exception):
421-
"""Prints the details of a GoogleAdsException object.
422-
423-
Args:
424-
exception: an instance of GoogleAdsException.
425-
"""
426-
print(
427-
f'Request with ID "{exception.request_id}" failed with status '
428-
f'"{exception.error.code().name}" and includes the following errors:'
393+
response = ad_group_ad_service.mutate_ad_group_ads(
394+
customer_id=customer_id, operations=ad_group_ad_operations
429395
)
430-
for error in exception.failure.errors:
431-
print(f'\tError with message "{error.message}".')
432-
if error.location:
433-
for field_path_element in error.location.field_path_elements:
434-
print(f"\t\tOn field: {field_path_element.field_name}")
435-
sys.exit(1)
396+
print(f"Added {len(response.results)} ads:")
397+
for ad in response.results:
398+
print(f"Added an ad with resource name {ad.resource_name}")
399+
# [END add_ad_customizer_6]
436400

437401

438402
if __name__ == "__main__":
439403
# GoogleAdsClient will read the google-ads.yaml configuration file in the
440404
# home directory if none is specified.
441-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
405+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
442406

443407
parser = argparse.ArgumentParser(
444408
description=(
@@ -463,4 +427,16 @@ def _handle_googleads_exception(exception):
463427
)
464428
args = parser.parse_args()
465429

466-
main(googleads_client, args.customer_id, args.ad_group_ids)
430+
try:
431+
main(googleads_client, args.customer_id, args.ad_group_ids)
432+
except GoogleAdsException as ex:
433+
print(
434+
f'Request with ID "{ex.request_id}" failed with status '
435+
f'"{ex.error.code().name}" and includes the following errors:'
436+
)
437+
for error in ex.failure.errors:
438+
print(f'Error with message "{error.message}".')
439+
if error.location:
440+
for field_path_element in error.location.field_path_elements:
441+
print(f"\t\tOn field: {field_path_element.field_name}")
442+
sys.exit(1)

examples/advanced_operations/add_ad_group_bid_modifier.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def main(client, customer_id, ad_group_id, bid_modifier_value):
6565
if __name__ == "__main__":
6666
# GoogleAdsClient will read the google-ads.yaml configuration file in the
6767
# home directory if none is specified.
68-
googleads_client = GoogleAdsClient.load_from_storage(version="v8")
68+
googleads_client = GoogleAdsClient.load_from_storage(version="v9")
6969

7070
parser = argparse.ArgumentParser(
7171
description=(

0 commit comments

Comments
 (0)