-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Deprecate v3_0 - Add log masking for CustomerUserAccessInvitation.email_address field. - Update examples to reflect changes to resource name helper methods.
- Loading branch information
Showing
3,114 changed files
with
19,768 additions
and
220,744 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""This code example retrieves pending invitations for a customer account. | ||
To create a pending invitation, see the invite_user_with_access_role.py | ||
example. | ||
""" | ||
|
||
|
||
import argparse | ||
import sys | ||
|
||
from google.ads.google_ads.client import GoogleAdsClient | ||
from google.ads.google_ads.errors import GoogleAdsException | ||
|
||
|
||
def main(client, customer_id): | ||
"""The main method that creates all necessary entities for the example. | ||
Args: | ||
client: An initialized GoogleAdsClient instance. | ||
customer_id: The client customer ID str. | ||
""" | ||
google_ads_service = client.get_service("GoogleAdsService", version="v6") | ||
# [START get_pending_invitations] | ||
query = """ | ||
SELECT | ||
customer_user_access_invitation.invitation_id, | ||
customer_user_access_invitation.email_address, | ||
customer_user_access_invitation.access_role, | ||
customer_user_access_invitation.creation_date_time | ||
FROM customer_user_access_invitation | ||
WHERE customer_user_access_invitation.invitation_status = PENDING""" | ||
|
||
try: | ||
response = google_ads_service.search_stream(customer_id, query=query) | ||
for batch in response: | ||
for row in batch.results: | ||
invite = row.customer_user_access_invitation | ||
print( | ||
"A pending invitation with " | ||
f"invitation ID: '{invite.invitation_id}', " | ||
f"email address: {invite.email_address}, " | ||
f"access role: {invite.access_role}, and " | ||
f"created on: {invite.creation_date_time} was found." | ||
) | ||
except GoogleAdsException as ex: | ||
print( | ||
f'Request with ID "{ex.request_id}" failed with status ' | ||
f'"{ex.error.code().name}" and includes the following errors:' | ||
) | ||
for error in ex.failure.errors: | ||
print(f'\tError with message "{error.message}".') | ||
if error.location: | ||
for field_path_element in error.location.field_path_elements: | ||
print(f"\t\tOn field: {field_path_element.field_name}") | ||
sys.exit(1) | ||
# [END get_pending_invitations] | ||
|
||
if __name__ == "__main__": | ||
# GoogleAdsClient will read the google-ads.yaml configuration file in the | ||
# home directory if none is specified. | ||
google_ads_client = GoogleAdsClient.load_from_storage() | ||
|
||
parser = argparse.ArgumentParser( | ||
description=("Retrieves pending invitations for a customer account.") | ||
) | ||
# The following argument(s) should be provided to run the example. | ||
parser.add_argument( | ||
"-c", | ||
"--customer_id", | ||
type=str, | ||
required=True, | ||
help="The Google Ads customer ID.", | ||
) | ||
args = parser.parse_args() | ||
|
||
main(google_ads_client, args.customer_id) |
116 changes: 116 additions & 0 deletions
116
examples/account_management/invite_user_with_access_role.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""This code example sends an invitation email to a user. | ||
The invitation is to manage a customer account with a desired access role. | ||
""" | ||
|
||
|
||
import argparse | ||
import sys | ||
|
||
from google.ads.google_ads.client import GoogleAdsClient | ||
from google.ads.google_ads.errors import GoogleAdsException | ||
|
||
|
||
def main(client, customer_id, email_address, access_role): | ||
"""The main method that creates all necessary entities for the example. | ||
Args: | ||
client: An initialized GoogleAdsClient instance. | ||
customer_id: The client customer ID str. | ||
email_address: The email address for the user receiving the invitation. | ||
access_role: The desired access role for the invitee. | ||
""" | ||
service = client.get_service( | ||
"CustomerUserAccessInvitationService", version="v6" | ||
) | ||
# [START invite_user_with_access_role] | ||
invitation_operation = client.get_type( | ||
"CustomerUserAccessInvitationOperation", version="v6" | ||
) | ||
invitation = invitation_operation.create | ||
invitation.email_address = email_address | ||
invitation.access_role = client.get_type( | ||
"AccessRoleEnum", version="v6" | ||
).AccessRole.Value(access_role) | ||
try: | ||
response = service.mutate_customer_user_access_invitation( | ||
customer_id, invitation_operation | ||
) | ||
print( | ||
"Customer user access invitation was sent for " | ||
f"customer ID: '{customer_id}', " | ||
f"email address {email_address}, and " | ||
f"access role {access_role}. The invitation resource name is: " | ||
f"{response.result.resource_name}" | ||
) | ||
except GoogleAdsException as ex: | ||
print( | ||
f'Request with ID "{ex.request_id}" failed with status ' | ||
f'"{ex.error.code().name}" and includes the following errors:' | ||
) | ||
for error in ex.failure.errors: | ||
print(f'\tError with message "{error.message}".') | ||
if error.location: | ||
for field_path_element in error.location.field_path_elements: | ||
print(f"\t\tOn field: {field_path_element.field_name}") | ||
sys.exit(1) | ||
# [END invite_user_with_access_role] | ||
|
||
if __name__ == "__main__": | ||
# GoogleAdsClient will read the google-ads.yaml configuration file in the | ||
# home directory if none is specified. | ||
google_ads_client = GoogleAdsClient.load_from_storage() | ||
|
||
parser = argparse.ArgumentParser( | ||
description=( | ||
"Sends an invitation email to a user to manage a customer " | ||
"account with a desired access role." | ||
) | ||
) | ||
# The following argument(s) should be provided to run the example. | ||
parser.add_argument( | ||
"-c", | ||
"--customer_id", | ||
type=str, | ||
required=True, | ||
help="The Google Ads customer ID.", | ||
) | ||
parser.add_argument( | ||
"-e", | ||
"--email_address", | ||
type=str, | ||
required=True, | ||
help="The email address of the user to send the invitation to.", | ||
) | ||
parser.add_argument( | ||
"-a", | ||
"--access_role", | ||
type=str, | ||
required=True, | ||
choices=google_ads_client.get_type( | ||
"AccessRoleEnum", version="v6" | ||
).AccessRole.keys(), | ||
help="The updated user access role.", | ||
) | ||
args = parser.parse_args() | ||
|
||
main( | ||
google_ads_client, | ||
args.customer_id, | ||
args.email_address, | ||
args.access_role, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.