Skip to content

Commit 3fc43d2

Browse files
committed
Update annotations in account_management
Change-Id: Ibfc7606f8c05f5a0528738a3c0905e518fd627b9
1 parent b9135c9 commit 3fc43d2

9 files changed

+303
-114
lines changed

examples/account_management/create_customer.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,26 @@
2727

2828
from google.ads.googleads.client import GoogleAdsClient
2929
from google.ads.googleads.errors import GoogleAdsException
30-
from google.ads.googleads.v19.resources.types.customer import Customer
31-
from google.ads.googleads.v19.services.services.customer_service.client import CustomerServiceClient
32-
from google.ads.googleads.v19.services.types.customer_service import CreateCustomerClientResponse
33-
30+
from google.ads.googleads.v20.resources.types.customer import Customer
31+
from google.ads.googleads.v20.services.services.customer_service.client import (
32+
CustomerServiceClient,
33+
)
34+
from google.ads.googleads.v20.services.types.customer_service import (
35+
CreateCustomerClientResponse,
36+
)
3437

3538

3639
# [START create_customer]
3740
def main(client: GoogleAdsClient, manager_customer_id: str) -> None:
38-
customer_service: CustomerServiceClient = client.get_service("CustomerService")
41+
"""The main method that creates all necessary entities for the example.
42+
43+
Args:
44+
client: an initialized GoogleAdsClient instance.
45+
manager_customer_id: a manager client customer ID.
46+
"""
47+
customer_service: CustomerServiceClient = client.get_service(
48+
"CustomerService"
49+
)
3950
customer: Customer = client.get_type("Customer")
4051
now: str = datetime.today().strftime("%Y%m%d %H:%M:%S")
4152
customer.descriptive_name = f"Account created with CustomerService on {now}"
@@ -47,11 +58,13 @@ def main(client: GoogleAdsClient, manager_customer_id: str) -> None:
4758
# options see: https://support.google.com/google-ads/answer/6305348
4859
customer.tracking_url_template = "{lpurl}?device={device}"
4960
customer.final_url_suffix = (
50-
"keyword={keyword}&matchtype={matchtype}" "&adgroupid={adgroupid}"
61+
"keyword={keyword}&matchtype={matchtype}&adgroupid={adgroupid}"
5162
)
5263

53-
response: CreateCustomerClientResponse = customer_service.create_customer_client(
54-
customer_id=manager_customer_id, customer_client=customer
64+
response: CreateCustomerClientResponse = (
65+
customer_service.create_customer_client(
66+
customer_id=manager_customer_id, customer_client=customer
67+
)
5568
)
5669
print(
5770
f'Customer created with resource name "{response.resource_name}" '

examples/account_management/get_account_hierarchy.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,27 @@
2828

2929
from google.ads.googleads.client import GoogleAdsClient
3030
from google.ads.googleads.errors import GoogleAdsException
31-
from google.ads.googleads.v19.services.services.google_ads_service.client import GoogleAdsServiceClient
32-
from google.ads.googleads.v19.services.services.customer_service.client import CustomerServiceClient
33-
from google.ads.googleads.v19.resources.types.customer_client import CustomerClient
34-
from google.ads.googleads.v19.services.types.google_ads_service import SearchPagedResponse, GoogleAdsRow
31+
from google.ads.googleads.v20.services.services.google_ads_service.client import (
32+
GoogleAdsServiceClient,
33+
)
34+
from google.ads.googleads.v20.services.services.customer_service.client import (
35+
CustomerServiceClient,
36+
)
37+
from google.ads.googleads.v20.resources.types.customer_client import (
38+
CustomerClient,
39+
)
40+
from google.ads.googleads.v20.services.types.google_ads_service import (
41+
SearchPagedResponse,
42+
GoogleAdsRow,
43+
)
44+
3545
# ListAccessibleCustomersResponse is not directly used for a variable type,
3646
# but its attribute .resource_names is used, which is List[str].
3747

38-
def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> None:
48+
49+
def main(
50+
client: GoogleAdsClient, login_customer_id: Optional[str] = None
51+
) -> None:
3952
"""Gets the account hierarchy of the given MCC and login customer ID.
4053
4154
Args:
@@ -44,10 +57,13 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
4457
method will instead list the accounts accessible from the
4558
authenticated Google Ads account.
4659
"""
47-
4860
# Gets instances of the GoogleAdsService and CustomerService clients.
49-
googleads_service: GoogleAdsServiceClient = client.get_service("GoogleAdsService")
50-
customer_service: CustomerServiceClient = client.get_service("CustomerService")
61+
googleads_service: GoogleAdsServiceClient = client.get_service(
62+
"GoogleAdsService"
63+
)
64+
customer_service: CustomerServiceClient = client.get_service(
65+
"CustomerService"
66+
)
5167

5268
# A collection of customer IDs to handle.
5369
seed_customer_ids: List[str] = []
@@ -90,7 +106,9 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
90106
print(customer_id_from_parse)
91107
seed_customer_ids.append(customer_id_from_parse)
92108

93-
for seed_customer_id_str in seed_customer_ids: # seed_customer_id_str is a string
109+
for (
110+
seed_customer_id_str
111+
) in seed_customer_ids: # seed_customer_id_str is a string
94112
# Performs a breadth-first search to build a Dictionary that maps
95113
# managers to their child accounts (customerIdsToChildAccounts).
96114
# unprocessed_customer_ids should store integers.
@@ -99,16 +117,21 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
99117
root_customer_client: CustomerClient | None = None
100118

101119
while unprocessed_customer_ids:
102-
customer_id_loop: int = unprocessed_customer_ids.pop(0) # customer_id_loop is an int
120+
customer_id_loop: int = unprocessed_customer_ids.pop(
121+
0
122+
) # customer_id_loop is an int
103123
# The search method expects customer_id to be a string.
104124
response: SearchPagedResponse = googleads_service.search(
105125
customer_id=str(customer_id_loop), query=query
106126
)
107127

108128
# Iterates over all rows in all pages to get all customer
109129
# clients under the specified customer's hierarchy.
110-
for googleads_row: GoogleAdsRow in response:
111-
customer_client_loop_var: CustomerClient = googleads_row.customer_client
130+
googleads_row: GoogleAdsRow
131+
for googleads_row in response:
132+
customer_client_loop_var: CustomerClient = (
133+
googleads_row.customer_client
134+
)
112135

113136
# The customer client that with level 0 is the specified
114137
# customer.
@@ -134,10 +157,13 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
134157
# need to check if it's already in the Dictionary.
135158
# Assuming customer_client_loop_var.id is an int
136159
if (
137-
customer_client_loop_var.id not in customer_ids_to_child_accounts
160+
customer_client_loop_var.id
161+
not in customer_ids_to_child_accounts
138162
and customer_client_loop_var.level == 1
139163
):
140-
unprocessed_customer_ids.append(customer_client_loop_var.id)
164+
unprocessed_customer_ids.append(
165+
customer_client_loop_var.id
166+
)
141167

142168
if root_customer_client is not None:
143169
print(
@@ -156,7 +182,9 @@ def main(client: GoogleAdsClient, login_customer_id: Optional[str] = None) -> No
156182

157183

158184
def print_account_hierarchy(
159-
customer_client: CustomerClient, customer_ids_to_child_accounts: Dict[int, List[CustomerClient]], depth: int
185+
customer_client: CustomerClient,
186+
customer_ids_to_child_accounts: Dict[int, List[CustomerClient]],
187+
depth: int,
160188
) -> None:
161189
"""Prints the specified account's hierarchy using recursion.
162190
@@ -182,7 +210,8 @@ def print_account_hierarchy(
182210

183211
# Recursively call this function for all child accounts of customer_client.
184212
if customer_id_print in customer_ids_to_child_accounts:
185-
for child_account: CustomerClient in customer_ids_to_child_accounts[customer_id_print]:
213+
child_account: CustomerClient
214+
for child_account in customer_ids_to_child_accounts[customer_id_print]:
186215
print_account_hierarchy(
187216
child_account, customer_ids_to_child_accounts, depth + 1
188217
)

examples/account_management/get_change_details.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@
2828
from google.ads.googleads.client import GoogleAdsClient
2929
from google.ads.googleads.errors import GoogleAdsException
3030
from google.ads.googleads.util import get_nested_attr
31-
from google.ads.googleads.v19.services.services.google_ads_service.client import GoogleAdsServiceClient
32-
from google.ads.googleads.v19.services.types.google_ads_service import SearchGoogleAdsRequest, SearchPagedResponse, GoogleAdsRow
33-
from google.ads.googleads.v19.resources.types.change_event import ChangeEvent
31+
from google.ads.googleads.v20.services.services.google_ads_service.client import (
32+
GoogleAdsServiceClient,
33+
)
34+
from google.ads.googleads.v20.services.types.google_ads_service import (
35+
SearchGoogleAdsRequest,
36+
SearchPagedResponse,
37+
GoogleAdsRow,
38+
)
39+
from google.ads.googleads.v20.resources.types.change_event import ChangeEvent
3440

3541

3642
# [START get_change_details]
@@ -41,7 +47,9 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
4147
client: The Google Ads client.
4248
customer_id: The Google Ads customer ID.
4349
"""
44-
googleads_service: GoogleAdsServiceClient = client.get_service("GoogleAdsService")
50+
googleads_service: GoogleAdsServiceClient = client.get_service(
51+
"GoogleAdsService"
52+
)
4553

4654
# Construct a query to find details for recent changes in your account.
4755
# The LIMIT clause is required for the change_event resource.
@@ -70,13 +78,18 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
7078
ORDER BY change_event.change_date_time DESC
7179
LIMIT 5"""
7280

73-
search_request: SearchGoogleAdsRequest = client.get_type("SearchGoogleAdsRequest")
81+
search_request: SearchGoogleAdsRequest = client.get_type(
82+
"SearchGoogleAdsRequest"
83+
)
7484
search_request.customer_id = customer_id
7585
search_request.query = query
7686

77-
results: SearchPagedResponse = googleads_service.search(request=search_request)
87+
results: SearchPagedResponse = googleads_service.search(
88+
request=search_request
89+
)
7890

79-
for row: GoogleAdsRow in results:
91+
row: GoogleAdsRow
92+
for row in results:
8093
event: ChangeEvent = row.change_event
8194
resource_type: str = event.change_resource_type.name
8295
old_resource: Any
@@ -174,7 +187,9 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
174187
if operation_type == "CREATE":
175188
print(f"\t{changed_field} set to {new_value}")
176189
else:
177-
old_value: Any = get_nested_attr(old_resource, changed_field)
190+
old_value: Any = get_nested_attr(
191+
old_resource, changed_field
192+
)
178193
# If the field value is an Enum get the human readable name
179194
# so that it is printed instead of the field ID integer.
180195
if isinstance(type(old_value), ProtoEnumMeta):

examples/account_management/get_change_summary.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222

2323
from google.ads.googleads.client import GoogleAdsClient
2424
from google.ads.googleads.errors import GoogleAdsException
25-
from google.ads.googleads.v19.services.services.google_ads_service.client import GoogleAdsServiceClient
26-
from google.ads.googleads.v19.services.types.google_ads_service import SearchGoogleAdsRequest, SearchPagedResponse, GoogleAdsRow
27-
from google.ads.googleads.v19.resources.types.change_status import ChangeStatus
25+
from google.ads.googleads.v20.services.services.google_ads_service.client import (
26+
GoogleAdsServiceClient,
27+
)
28+
from google.ads.googleads.v20.services.types.google_ads_service import (
29+
SearchGoogleAdsRequest,
30+
SearchPagedResponse,
31+
GoogleAdsRow,
32+
)
33+
from google.ads.googleads.v20.resources.types.change_status import ChangeStatus
2834

2935

3036
# [START get_change_summary]
@@ -49,13 +55,16 @@ def main(client: GoogleAdsClient, customer_id: str) -> None:
4955
ORDER BY change_status.last_change_date_time
5056
LIMIT 10000"""
5157

52-
search_request: SearchGoogleAdsRequest = client.get_type("SearchGoogleAdsRequest")
58+
search_request: SearchGoogleAdsRequest = client.get_type(
59+
"SearchGoogleAdsRequest"
60+
)
5361
search_request.customer_id = customer_id
5462
search_request.query = query
5563

5664
response: SearchPagedResponse = ads_service.search(request=search_request)
5765

58-
for row: GoogleAdsRow in response:
66+
row: GoogleAdsRow
67+
for row in response:
5968
cs: ChangeStatus = row.change_status
6069
resource_type: str = cs.resource_type.name
6170
resource_name: str

examples/account_management/invite_user_with_access_role.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,28 @@
2323

2424
from google.ads.googleads.client import GoogleAdsClient
2525
from google.ads.googleads.errors import GoogleAdsException
26-
from google.ads.googleads.v19.services.services.customer_user_access_invitation_service.client import CustomerUserAccessInvitationServiceClient
27-
from google.ads.googleads.v19.services.types.customer_user_access_invitation_service import CustomerUserAccessInvitationOperation, MutateCustomerUserAccessInvitationResponse
28-
from google.ads.googleads.v19.resources.types.customer_user_access_invitation import CustomerUserAccessInvitation
26+
from google.ads.googleads.v20.services.services.customer_user_access_invitation_service.client import (
27+
CustomerUserAccessInvitationServiceClient,
28+
)
29+
from google.ads.googleads.v20.services.types.customer_user_access_invitation_service import (
30+
CustomerUserAccessInvitationOperation,
31+
MutateCustomerUserAccessInvitationResponse,
32+
)
33+
from google.ads.googleads.v20.resources.types.customer_user_access_invitation import (
34+
CustomerUserAccessInvitation,
35+
)
36+
2937
# AccessRoleEnum is part of google.ads.googleads.v19.enums.types.access_role
3038
# but it's accessed via client.enums.AccessRoleEnum, so direct import for type hint might not be strictly needed for the parameter.
3139
# The field invitation.access_role expects an int (the enum value).
3240

33-
def main(client: GoogleAdsClient, customer_id: str, email_address: str, access_role: str) -> None:
41+
42+
def main(
43+
client: GoogleAdsClient,
44+
customer_id: str,
45+
email_address: str,
46+
access_role: str,
47+
) -> None:
3448
"""The main method that creates all necessary entities for the example.
3549
3650
Args:
@@ -39,19 +53,23 @@ def main(client: GoogleAdsClient, customer_id: str, email_address: str, access_r
3953
email_address: The email address for the user receiving the invitation.
4054
access_role: The desired access role for the invitee (e.g., "ADMIN", "STANDARD").
4155
"""
42-
service: CustomerUserAccessInvitationServiceClient = client.get_service("CustomerUserAccessInvitationService")
56+
service: CustomerUserAccessInvitationServiceClient = client.get_service(
57+
"CustomerUserAccessInvitationService"
58+
)
4359
# [START invite_user_with_access_role]
44-
invitation_operation: CustomerUserAccessInvitationOperation = client.get_type(
45-
"CustomerUserAccessInvitationOperation"
60+
invitation_operation: CustomerUserAccessInvitationOperation = (
61+
client.get_type("CustomerUserAccessInvitationOperation")
4662
)
4763
invitation: CustomerUserAccessInvitation = invitation_operation.create
4864
invitation.email_address = email_address
4965
# The access_role field in the CustomerUserAccessInvitation message expects
5066
# an AccessRoleEnum value (which is an int).
5167
invitation.access_role = client.enums.AccessRoleEnum[access_role].value
5268

53-
response: MutateCustomerUserAccessInvitationResponse = service.mutate_customer_user_access_invitation(
54-
customer_id=customer_id, operation=invitation_operation
69+
response: MutateCustomerUserAccessInvitationResponse = (
70+
service.mutate_customer_user_access_invitation(
71+
customer_id=customer_id, operation=invitation_operation
72+
)
5573
)
5674
print(
5775
"Customer user access invitation was sent for "

0 commit comments

Comments
 (0)