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

Skip to content

Commit f647278

Browse files
authored
Update link_manager_to_client example (googleads#467)
1 parent 4676d65 commit f647278

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

examples/account_management/link_manager_to_client.py

+17-25
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def main(client, customer_id, manager_customer_id):
3838
# Extend an invitation to the client while authenticating as the manager.
3939
client_link_operation = client.get_type("CustomerClientLinkOperation")
4040
client_link = client_link_operation.create
41-
client_link.client_customer = f"customers/{customer_id}"
41+
client_link.client_customer = customer_client_link_service.customer_path(customer_id)
4242
client_link.status = client.enums.ManagerLinkStatusEnum.PENDING
4343

4444
response = customer_client_link_service.mutate_customer_client_link(
@@ -97,31 +97,14 @@ def main(client, customer_id, manager_customer_id):
9797
protobuf_helpers.field_mask(None, manager_link._pb),
9898
)
9999

100-
try:
101-
response = customer_manager_link_service.mutate_customer_manager_link(
102-
customer_id=manager_customer_id, operations=[manager_link_operation]
103-
)
104-
resource_name = response.results[0].resource_name
105-
print(
106-
"Client accepted invitation with resource_name: "
107-
f'"{resource_name}"'
108-
)
109-
except GoogleAdsException as ex:
110-
_handle_googleads_exception(ex)
111-
# [END link_manager_to_client]
112-
113-
114-
def _handle_googleads_exception(exception):
100+
response = customer_manager_link_service.mutate_customer_manager_link(
101+
customer_id=manager_customer_id, operations=[manager_link_operation]
102+
)
115103
print(
116-
f'Request with ID "{exception.request_id}" failed with status '
117-
f'"{exception.error.code().name}" and includes the following errors:'
104+
"Client accepted invitation with resource_name: "
105+
f'"{response.results[0].resource_name}"'
118106
)
119-
for error in exception.failure.errors:
120-
print(f'\tError with message "{error.message}".')
121-
if error.location:
122-
for field_path_element in error.location.field_path_elements:
123-
print(f"\t\tOn field: {field_path_element.field_name}")
124-
sys.exit(1)
107+
# [END link_manager_to_client]
125108

126109

127110
if __name__ == "__main__":
@@ -150,4 +133,13 @@ def _handle_googleads_exception(exception):
150133
try:
151134
main(googleads_client, args.customer_id, args.manager_customer_id)
152135
except GoogleAdsException as ex:
153-
_handle_googleads_exception(ex)
136+
print(
137+
f'Request with ID "{exception.request_id}" failed with status '
138+
f'"{exception.error.code().name}" and includes the following errors:'
139+
)
140+
for error in exception.failure.errors:
141+
print(f'\tError with message "{error.message}".')
142+
if error.location:
143+
for field_path_element in error.location.field_path_elements:
144+
print(f"\t\tOn field: {field_path_element.field_name}")
145+
sys.exit(1)

0 commit comments

Comments
 (0)