Skip to content

Commit 8ed125a

Browse files
authored
Changes for release v6_0 and deprecation of v2_0. (googleads#335)
1 parent 599541b commit 8ed125a

2,943 files changed

Lines changed: 205156 additions & 170682 deletions

File tree

Some content is hidden

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

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* 8.0.0
2+
- Google Ads v6_0 release
3+
- Deprecate v2_0
4+
- Update all examples to support migration from wrapper types to primitives.
5+
- Add masking logic to prevent PII in requests/responses from being logged.
6+
17
* 7.0.0
28
- Google Ads v5_0 release
39
- Updates to examples to support addition of field presence on certain

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Authors
4141
* `Mark Saniscalchi`_
4242
* `David Wihl`_
4343
* `Ben Karl`_
44+
* `Andrew Burke`_
4445

4546
.. |build-status| image:: https://storage.googleapis.com/gaa-clientlibs/badges/google-ads-python/buildstatus_ubuntu.svg
4647
.. _Developer Site: https://developers.google.com/google-ads/api/docs/client-libs/python/
@@ -50,3 +51,4 @@ Authors
5051
.. _Mark Saniscalchi: https://github.com/msaniscalchi
5152
.. _David Wihl: https://github.com/wihl
5253
.. _Ben Karl: https://github.com/BenRKarl
54+
.. _Andrew Burke: https://github.com/AndrewMBurke

examples/account_management/create_customer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030

3131
def main(client, manager_customer_id):
32-
customer_service = client.get_service("CustomerService", version="v5")
33-
customer = client.get_type("Customer", version="v5")
32+
customer_service = client.get_service("CustomerService", version="v6")
33+
customer = client.get_type("Customer", version="v6")
3434
today = datetime.today().strftime("%Y%m%d %H:%M:%S")
3535
customer.descriptive_name = (
3636
"Account created with " "CustomerService on %s" % today

examples/account_management/get_account_changes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def resource_name_for_resource_type(resource_type, row):
5656

5757

5858
def main(client, customer_id):
59-
ads_service = client.get_service("GoogleAdsService", version="v5")
59+
ads_service = client.get_service("GoogleAdsService", version="v6")
6060
query = """
6161
SELECT
6262
change_status.resource_name,
@@ -77,10 +77,10 @@ def main(client, customer_id):
7777
)
7878

7979
resource_type_enum = client.get_type(
80-
"ChangeStatusResourceTypeEnum", version="v5"
80+
"ChangeStatusResourceTypeEnum", version="v6"
8181
).ChangeStatusResourceType
8282
change_status_operation_enum = client.get_type(
83-
"ChangeStatusOperationEnum", version="v5"
83+
"ChangeStatusOperationEnum", version="v6"
8484
).ChangeStatusOperation
8585

8686
try:
@@ -95,7 +95,7 @@ def main(client, customer_id):
9595
'On "%s", change status "%s" shows a resource type of "%s" '
9696
'with resource name "%s" was "%s".'
9797
% (
98-
row.change_status.last_change_date_time.value,
98+
row.change_status.last_change_date_time,
9999
row.change_status.resource_name,
100100
resource_type,
101101
resource_name_for_resource_type(resource_type, row),

examples/account_management/get_account_hierarchy.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def main(client, login_customer_id=None):
4040
"""
4141

4242
# Gets instances of the GoogleAdsService and CustomerService clients.
43-
google_ads_service = client.get_service("GoogleAdsService", version="v5")
44-
customer_service = client.get_service("CustomerService", version="v5")
43+
google_ads_service = client.get_service("GoogleAdsService", version="v6")
44+
customer_service = client.get_service("CustomerService", version="v6")
4545

4646
# A collection of customer IDs to handle.
4747
seed_customer_ids = []
@@ -99,7 +99,7 @@ def main(client, login_customer_id=None):
9999

100100
# The customer client that with level 0 is the specified
101101
# customer.
102-
if customer_client.level.value == 0:
102+
if customer_client.level == 0:
103103
if root_customer_client is None:
104104
root_customer_client = customer_client
105105
continue
@@ -115,23 +115,21 @@ def main(client, login_customer_id=None):
115115
customer_client
116116
)
117117

118-
if customer_client.manager.value:
118+
if customer_client.manager:
119119
# A customer can be managed by multiple managers, so to
120120
# prevent visiting the same customer many times, we
121121
# need to check if it's already in the Dictionary.
122122
if (
123-
customer_client.id.value
123+
customer_client.id
124124
not in customer_ids_to_child_accounts
125-
and customer_client.level.value == 1
125+
and customer_client.level == 1
126126
):
127-
unprocessed_customer_ids.append(
128-
customer_client.id.value
129-
)
127+
unprocessed_customer_ids.append(customer_client.id)
130128

131129
if root_customer_client is not None:
132130
print(
133131
"The hierarchy of customer ID "
134-
f"{root_customer_client.id.value} is printed below:"
132+
f"{root_customer_client.id} is printed below:"
135133
)
136134
print_account_hierarchy(
137135
root_customer_client, customer_ids_to_child_accounts, 0
@@ -172,12 +170,12 @@ def print_account_hierarchy(
172170
if depth == 0:
173171
print("Customer ID (Descriptive Name, Currency Code, Time Zone)")
174172

175-
customer_id = str(customer_client.id.value)
173+
customer_id = str(customer_client.id)
176174
print("-" * (depth * 2), end="")
177175
print(
178-
f"{customer_id} ({customer_client.descriptive_name.value}, "
179-
f"{customer_client.currency_code.value}, "
180-
f"{customer_client.time_zone.value})"
176+
f"{customer_id} ({customer_client.descriptive_name}, "
177+
f"{customer_client.currency_code}, "
178+
f"{customer_client.time_zone})"
181179
)
182180

183181
# Recursively call this function for all child accounts of customer_client.

examples/account_management/get_account_information.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
def main(client, customer_id):
28-
customer_service = client.get_service("CustomerService", version="v5")
28+
customer_service = client.get_service("CustomerService", version="v6")
2929

3030
resource_name = customer_service.customer_path(customer_id)
3131

examples/account_management/link_manager_to_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def main(client, customer_id, manager_customer_id):
3232

3333
# Extend an invitation to the client while authenticating as the manager.
3434
client_link_operation = client.get_type(
35-
"CustomerClientLinkOperation", version="v5"
35+
"CustomerClientLinkOperation", version="v6"
3636
)
3737
client_link = client_link_operation.create
38-
client_link.client_customer.value = "customers/{}".format(customer_id)
38+
client_link.client_customer = "customers/{}".format(customer_id)
3939
client_link.status = client.get_type("ManagerLinkStatusEnum").PENDING
4040

4141
customer_client_link_service = client.get_service(
42-
"CustomerClientLinkService", version="v5"
42+
"CustomerClientLinkService", version="v6"
4343
)
4444
response = customer_client_link_service.mutate_customer_client_link(
4545
manager_customer_id, client_link_operation
@@ -62,7 +62,7 @@ def main(client, customer_id, manager_customer_id):
6262
FROM customer_client_link
6363
WHERE customer_client_link.resource_name = '{resource_name}'"""
6464

65-
ga_service = client.get_service("GoogleAdsService", version="v5")
65+
ga_service = client.get_service("GoogleAdsService", version="v6")
6666
response = ga_service.search(manager_customer_id, query=query)
6767

6868
# Since the google_ads_service.search method returns an iterator we need
@@ -72,19 +72,19 @@ def main(client, customer_id, manager_customer_id):
7272
manager_link_id = row.customer_client_link.manager_link_id
7373

7474
manager_link_operation = client.get_type(
75-
"CustomerManagerLinkOperation", version="v5"
75+
"CustomerManagerLinkOperation", version="v6"
7676
)
7777
manager_link = manager_link_operation.update
7878
manager_link.resource_name = "customers/{}/customerManagerLinks/{}~{}".format(
7979
customer_id, manager_customer_id, manager_link_id
8080
)
8181

82-
manager_link.status = client.get_type("ManagerLinkStatusEnum", version="v5")
82+
manager_link.status = client.get_type("ManagerLinkStatusEnum", version="v6")
8383
field_mask = protobuf_helpers.field_mask(None, manager_link)
8484
manager_link_operation.update_mask.CopyFrom(field_mask)
8585

8686
manager_link_service = client.get_service(
87-
"ManagerLinkService", version="v5"
87+
"ManagerLinkService", version="v6"
8888
)
8989
response = manager_link_service.mutate_manager_links(
9090
manager_customer_id, [manager_link_operation]
@@ -105,7 +105,7 @@ def main(client, customer_id, manager_customer_id):
105105

106106
parser = argparse.ArgumentParser(
107107
description=(
108-
"Links and existing manager customer to an existing"
108+
"Links an existing manager customer to an existing"
109109
"client customer"
110110
)
111111
)

examples/account_management/list_accessible_customers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def main(client):
30-
customer_service = client.get_service("CustomerService", version="v5")
30+
customer_service = client.get_service("CustomerService", version="v6")
3131

3232
try:
3333
accessible_customers = customer_service.list_accessible_customers()
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/usr/bin/env python
2+
# Copyright 2020 Google LLC
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# https://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
"""Demonstrates how to reject or unlink a Merchant Center link request.
16+
17+
Prerequisite: You need to have access to a Merchant Center account. You can find
18+
instructions to create a Merchant Center account here:
19+
https://support.google.com/merchants/answer/188924.
20+
21+
To run this example, you must use the Merchant Center UI or the Content API for
22+
Shopping to send a link request between your Merchant Center and Google Ads
23+
accounts. You can find detailed instructions to link your Merchant Center and
24+
Google Ads accounts here: https://support.google.com/merchants/answer/6159060.
25+
"""
26+
27+
import argparse
28+
import sys
29+
30+
from google.ads.google_ads.client import GoogleAdsClient
31+
from google.ads.google_ads.errors import GoogleAdsException
32+
33+
34+
def main(client, customer_id, merchant_center_account_id):
35+
"""Demonstrates how to reject a Merchant Center link request.
36+
37+
Args:
38+
client: An initialized Google Ads client.
39+
customer_id: The Google Ads customer ID.
40+
merchant_center_account_id: The Merchant Center account ID for the
41+
account requesting to link.
42+
"""
43+
# Get the MerchantCenterLinkService client.
44+
merchant_center_link_service = client.get_service(
45+
"MerchantCenterLinkService", version="v6"
46+
)
47+
try:
48+
# Get the extant customer account to Merchant Center account links.
49+
list_merchant_center_links_response = merchant_center_link_service.list_merchant_center_links(
50+
customer_id
51+
)
52+
53+
number_of_links = len(
54+
list_merchant_center_links_response.merchant_center_links
55+
)
56+
57+
if number_of_links <= 0:
58+
print(
59+
"There are no current merchant center links to Google Ads "
60+
f"account {customer_id}. This example will now exit."
61+
)
62+
return
63+
64+
print(
65+
f"{number_of_links} Merchant Center link(s) found with the "
66+
"following details:"
67+
)
68+
69+
merchant_center_link_status_enum = client.get_type(
70+
"MerchantCenterLinkStatusEnum", version="v6"
71+
).MerchantCenterLinkStatus
72+
73+
for merchant_center_link in list_merchant_center_links_response.merchant_center_links:
74+
print(
75+
f"\tLink '{merchant_center_link.resource_name}' has status "
76+
f"'{merchant_center_link_status_enum.Name(merchant_center_link.status)}'."
77+
)
78+
79+
# Check if this is the link to the target Merchant Center account.
80+
if merchant_center_link.id == merchant_center_account_id:
81+
# A Merchant Center link can be pending or enabled; in both
82+
# cases, we reject it by removing the link.
83+
_remove_merchant_center_link(
84+
client,
85+
merchant_center_link_service,
86+
customer_id,
87+
merchant_center_link,
88+
)
89+
90+
# We can terminate early since this example concerns only one
91+
# Google Ads account to Merchant Center account link.
92+
return
93+
94+
# Raise an exception if no matching Merchant Center link was found.
95+
raise ValueError(
96+
"No link could was found between Google Ads account "
97+
f"{customer_id} and Merchant Center account "
98+
f"{merchant_center_account_id}."
99+
)
100+
101+
except GoogleAdsException as ex:
102+
print(
103+
f'Request with ID "{ex.request_id}" failed with status '
104+
f'"{ex.error.code().name}" and includes the following errors:'
105+
)
106+
for error in ex.failure.errors:
107+
print(f'\tError with message "{error.message}".')
108+
if error.location:
109+
for field_path_element in error.location.field_path_elements:
110+
print(f"\t\tOn field: {field_path_element.field_name}")
111+
sys.exit(1)
112+
113+
114+
def _remove_merchant_center_link(
115+
client, merchant_center_link_service, customer_id, merchant_center_link
116+
):
117+
"""Removes a Merchant Center link from a Google Ads client customer account.
118+
119+
Args:
120+
client: An initialized Google Ads client.
121+
merchant_center_link_service: An initialized
122+
MerchantCenterLinkService client.
123+
customer_id: The Google Ads customer ID of the account that has the link
124+
request.
125+
merchant_center_link: The MerchantCenterLink object to remove.
126+
"""
127+
# Create a single remove operation, specifying the Merchant Center link
128+
# resource name.
129+
operation = client.get_type("MerchantCenterLinkOperation", version="v6")
130+
operation.remove = merchant_center_link.resource_name
131+
132+
# Send the operation in a mutate request.
133+
response = merchant_center_link_service.mutate_merchant_center_link(
134+
customer_id, operation
135+
)
136+
print(
137+
"Removed Merchant Center link with resource name "
138+
f"'{response.result.resource_name}'."
139+
)
140+
141+
142+
if __name__ == "__main__":
143+
# GoogleAdsClient will read the google-ads.yaml configuration file in the
144+
# home directory if none is specified.
145+
google_ads_client = GoogleAdsClient.load_from_storage()
146+
147+
parser = argparse.ArgumentParser(
148+
description=(
149+
"Demonstrates how to reject a Merchant Center link request."
150+
)
151+
)
152+
# The following argument(s) should be provided to run the example.
153+
parser.add_argument(
154+
"-c",
155+
"--customer_id",
156+
type=str,
157+
required=True,
158+
help="The Google Ads customer ID.",
159+
)
160+
parser.add_argument(
161+
"-m",
162+
"--merchant_center_account_id",
163+
type=int,
164+
required=True,
165+
help="The Merchant Center account ID for the account requesting to "
166+
"link.",
167+
)
168+
args = parser.parse_args()
169+
170+
main(google_ads_client, args.customer_id, args.merchant_center_account_id)

0 commit comments

Comments
 (0)