├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── check_job.py ├── create_and_populate_list.py ├── generate_refresh_token.py ├── googleads_config.yaml ├── requirements.txt └── third_party ├── googleads └── LICENSE └── oauth2client └── LICENSE /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows 28 | [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCLAIMER: This is not an officially supported Google product. 2 | 3 | # Customer Match upload script 4 | 5 | ## About 6 | 7 | This tool uploads Customer Match lists to Google Ads via API. 8 | 9 | ## Usage 10 | 11 | ### Google Ads setup 12 | 13 | Before running the script, you should create a remarketing list in Google Ads. 14 | It is recommended to set the membership duration to the N+3, where N is the 15 | number of days between script runs. This way, the list will be maintained with 16 | only those users that are in the audience file. If a user is removed from the 17 | file, it won't be added in the next script run and it will be eventually 18 | deleted. Matching process may take time; the *+3* is a safeguard period to avoid 19 | unwanted temporary removals during this processing time. 20 | 21 | ### Set-up 22 | 23 | First, you must obtain the appropriate credentials so that the script can 24 | connect to Google Ads API and upload the data. Follow the instructions 25 | [here](https://developers.google.com/google-ads/api/docs/oauth/cloud-project#create_a_client_id_and_client_secret) 26 | to obtain OAuth 2.0 Client IDs for an *Installed App*. Then, download the 27 | client secrets json file to the working directory (this file contains a 28 | *Client ID* and *Client secret*). 29 | 30 | Once you have the file, you must obtain a *Refresh token* using this script: 31 | 32 | ```shell 33 | python generate_refresh_token.py --client_secrets_path CLIENT_SECRETS_FILE 34 | ``` 35 | 36 | Where `CLIENT_SECRETS_FILE` must be substituted with the client secrets file 37 | path you downloaded previously. 38 | 39 | The script will generate a *Refresh token* and print it on screen. Make a copy 40 | of it as we'll need it later. 41 | 42 | Next, get a *Developer token* from Google Ads by following the instructions 43 | [here](https://developers.google.com/google-ads/api/docs/first-call/dev-token). 44 | 45 | Once you have the *Client ID*, *Client secret*, *Refresh token* and *Developer 46 | token*, you must add them to the script config file. In order to do so, edit the 47 | file `googleads_config.yaml` and enter the appropriate values. You'll also need 48 | the Google Ads *MCC Customer ID*, which you can find in Google Ads UI. 49 | 50 | ### Input preparation 51 | 52 | Your audience file should be named `audience.csv` and must be in CSV format. You 53 | must specify the fields to upload in the header row. The available fields are: 54 | 55 | - Email 56 | - Phone 57 | - FirstName 58 | - LastName 59 | - CountryCode 60 | - ZipCode 61 | - MobileId 62 | - UserId 63 | - List 64 | 65 | You can use plain text values and the script will hash them before uploading, or 66 | you can hash them yourself (the desired behaviour is controlled with the 67 | `--hash_required` flag in the script). 68 | 69 | Currently there are three types of customer lists available: 70 | 71 | - *Customers based on email, phone, and/or mailing address uploads* (`CONTACT_INFO`) 72 | - *Customers based on Mobile Device ID uploads* (`MOBILE_ADVERTISING_ID`) 73 | - *Customers based on User ID uploads* (`CRM_ID`) 74 | 75 | The type of list to upload is controlled using the `list_type`flag 76 | (the default value is `CONTACT_INFO`) 77 | 78 | Each type of list only allows certain fields to be uploaded. You need to take 79 | that into account while preparing the data. The script will filter those 80 | fields depending on the `list_type` specified, but if the lists already exists 81 | and doesn't match the type specified, it will show an error in the upload 82 | operation. 83 | 84 | These are the fields allowed per type: 85 | 86 | - `CONTACT_INFO`: 87 | - Email 88 | - Phone 89 | - FirstName 90 | - LastName 91 | - CountryCode 92 | - ZipCode 93 | - List 94 | - `MOBILE_ADVERTISING_ID`: 95 | - MobileId 96 | - List 97 | - `CRM_ID`: 98 | - UserId 99 | - List 100 | 101 | ### Running the script 102 | 103 | Once the configuration file is ready, and you have the audience file in 104 | `audience.csv` you can execute the script to upload the data to Google Ads: 105 | 106 | ```shell 107 | python create_and_populate_list.py --customer_id CUSTOMER_ID 108 | ``` 109 | 110 | Where `CUSTOMER_ID` represents the Customer ID of the account where the user 111 | list will be created. 112 | 113 | If your audience file doesn't contain a column for the audience name, you can 114 | specify a default audience to which all entries will be added. Here, 115 | `YOUR_AUDIENCE_NAME` will typically be the name of the audience you manually 116 | created in Google Ads for the purposes of this script: 117 | 118 | ```shell 119 | python create_and_populate_list.py --customer_id CUSTOMER_ID --audience_name YOUR_AUDIENCE_NAME 120 | ``` 121 | 122 | If you don't specify any remarketing list in the audience file, the script will 123 | create a new audience list with a default name (controlled by the `GENERIC_LIST` 124 | variable in the script) and will add all the users to that one. 125 | 126 | You can also specify the list type by using the `--list_type` flag, and passing 127 | one of the allowed values: `CONTACT_INFO`, `MOBILE_ADVERTISING_ID`,`CRM_ID`. 128 | The default if not specified is `CONTACT_INFO`. 129 | 130 | The data is not hashed by default. If you need the script to hash the customer 131 | data, you can use the `--hash_required` flag to enable it. 132 | 133 | The script has more optional parameters that allow working with custom 134 | configuration and audience file paths. For more info on them, run: 135 | 136 | ```shell 137 | python create_and_populate_list.py --help 138 | ``` 139 | 140 | ### Checking the results 141 | 142 | By default, the script launches the upload jobs, and returns. You can use the 143 | `--wait` flag to wait for the job to finish, but as the upload jobs can take up 144 | to 48 hours to finish, waiting is not recommended. 145 | 146 | If you don't specify the wait flag, the script will print the job ids in the 147 | standard output, and the command you can use to check the job status. 148 | 149 | This is an output example: 150 | 151 | ```txt 152 | Offline user data job ID '9999999' with type 'CUSTOMER_MATCH_USER_LIST' has status: RUNNING 153 | To check the status of the job periodically, use the following GAQL query with GoogleAdsService.Search: 154 | SELECT 155 | offline_user_data_job.resource_name, 156 | offline_user_data_job.id, 157 | offline_user_data_job.status, 158 | offline_user_data_job.type, 159 | offline_user_data_job.failure_reason 160 | FROM offline_user_data_job 161 | WHERE offline_user_data_job.resource_name = 162 | 'customers/0000000000/offlineUserDataJobs/9999999' 163 | LIMIT 1 164 | Or you can use the check_job.py script with the following args: 165 | 166 | python check_job.py --config_file ./csemcc_config.yaml --customer_id 0000000000 --job_resource_name customers/0000000000/offlineUserDataJobs/9999999 --user_list_resource_name customers/0000000000/userLists/888888888 167 | ``` 168 | -------------------------------------------------------------------------------- /check_job.py: -------------------------------------------------------------------------------- 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 | """Adds user lists and populates them with customer's CRM contact information. 16 | 17 | Note: It may take several hours for the list to be populated with members. Email 18 | addresses must be associated with a Google account. For privacy purposes, the 19 | user list size will show as zero until the list has at least 1000 members. After 20 | that, the size will be rounded to the two most significant digits. 21 | """ 22 | 23 | import argparse 24 | from google.ads.googleads.client import GoogleAdsClient 25 | from google.ads.googleads.errors import GoogleAdsException 26 | 27 | CONFIG_PATH = './googleads_config.yaml' 28 | 29 | 30 | def check_job_status( 31 | client, 32 | customer_id, 33 | offline_user_data_job_resource_name, 34 | user_list_resource_name, 35 | ): 36 | """Retrieves, checks, and prints the status of the offline user data job. 37 | 38 | Args: 39 | client: The Google Ads client. 40 | customer_id: The customer ID for which to add the user list. 41 | offline_user_data_job_resource_name: The resource name of the offline 42 | user data job to get the status of. 43 | user_list_resource_name: The resource name of the customer match user 44 | list 45 | """ 46 | query = f''' 47 | SELECT 48 | offline_user_data_job.resource_name, 49 | offline_user_data_job.id, 50 | offline_user_data_job.status, 51 | offline_user_data_job.type, 52 | offline_user_data_job.failure_reason 53 | FROM offline_user_data_job 54 | WHERE offline_user_data_job.resource_name = 55 | '{offline_user_data_job_resource_name}' 56 | LIMIT 1''' 57 | 58 | # Issues a search request using streaming. 59 | google_ads_service = client.get_service('GoogleAdsService') 60 | results = google_ads_service.search(customer_id=customer_id, query=query) 61 | offline_user_data_job = next(iter(results)).offline_user_data_job 62 | status_name = offline_user_data_job.status.name 63 | 64 | print(f'Offline user data job ID \'{offline_user_data_job.id}\' with type ' 65 | f'\'{offline_user_data_job.type_.name}\' has status: {status_name}') 66 | 67 | if status_name == 'SUCCESS': 68 | print_customer_match_user_list_info(client, customer_id, 69 | user_list_resource_name) 70 | elif status_name == 'FAILED': 71 | print(f'\tFailure Reason: {offline_user_data_job.failure_reason}') 72 | elif status_name in ('PENDING', 'RUNNING'): 73 | print('The job is still runnning.') 74 | 75 | 76 | def print_customer_match_user_list_info(client, customer_id, 77 | user_list_resource_name): 78 | """Prints information about the Customer Match user list. 79 | 80 | Args: 81 | client: The Google Ads client. 82 | customer_id: The customer ID for which to add the user list. 83 | user_list_resource_name: The resource name of the user list to which to 84 | add users. 85 | """ 86 | googleads_service_client = client.get_service('GoogleAdsService') 87 | 88 | # Creates a query that retrieves the user list. 89 | query = f''' 90 | SELECT 91 | user_list.size_for_display, 92 | user_list.size_for_search 93 | FROM user_list 94 | WHERE user_list.resource_name = '{user_list_resource_name}' 95 | ''' 96 | 97 | # Issues a search request. 98 | search_results = googleads_service_client.search( 99 | customer_id=customer_id, query=query) 100 | 101 | # Prints out some information about the user list. 102 | user_list = next(iter(search_results)).user_list 103 | print('The estimated number of users that the user list ' 104 | f'\'{user_list.resource_name}\' has is ' 105 | f'{user_list.size_for_display} for Display and ' 106 | f'{user_list.size_for_search} for Search.') 107 | print('Reminder: It may take several hours for the user list to be ' 108 | 'populated. Estimates of size zero are possible.') 109 | 110 | 111 | if __name__ == '__main__': 112 | parser = argparse.ArgumentParser( 113 | description='Check status of customer match list jobs in Google Ads.') 114 | parser.add_argument( 115 | '--config_file', 116 | default=CONFIG_PATH, 117 | help='Configuration file for Google Ads API access.') 118 | parser.add_argument( 119 | '--customer_id', 120 | required=True, 121 | help='The customer ID for which to add the user list.') 122 | parser.add_argument( 123 | '--job_resource_name', 124 | required=True, 125 | help='Offline user data job resource name to check.') 126 | parser.add_argument( 127 | '--user_list_resource_name', 128 | required=True, 129 | help='User list resource name.') 130 | args = parser.parse_args() 131 | 132 | google_ads_client = GoogleAdsClient.load_from_storage(args.config_file) 133 | 134 | try: 135 | check_job_status(google_ads_client, args.customer_id, 136 | args.job_resource_name, args.user_list_resource_name) 137 | except GoogleAdsException as ex: 138 | print(f'Request with ID "{ex.request_id}" failed with status ' 139 | f'"{ex.error.code().name}" and includes the following errors:') 140 | for single_error in ex.failure.errors: 141 | print(f'\tError with message "{single_error.message}".') 142 | if single_error.location: 143 | for field_path_element in single_error.location.field_path_elements: 144 | print(f'\t\tOn field: {field_path_element.field_name}') 145 | -------------------------------------------------------------------------------- /create_and_populate_list.py: -------------------------------------------------------------------------------- 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 | """Adds user lists and populates them with customer's CRM contact information. 16 | 17 | Note: It may take several hours for the list to be populated with members. Email 18 | addresses must be associated with a Google account. For privacy purposes, the 19 | user list size will show as zero until the list has at least 1000 members. After 20 | that, the size will be rounded to the two most significant digits. 21 | """ 22 | 23 | import argparse 24 | import csv 25 | import hashlib 26 | 27 | from google.ads.googleads.client import GoogleAdsClient 28 | from google.ads.googleads.errors import GoogleAdsException 29 | from google.ads.googleads.v10.enums.types import customer_match_upload_key_type 30 | from google.ads.googleads.v10.enums.types import offline_user_data_job_status 31 | from google.ads.googleads.v10.enums.types import offline_user_data_job_type 32 | 33 | # CSV Headers (Change if needed) 34 | HEADER_LINE = True 35 | EMAIL = 'Email' 36 | PHONE = 'Phone' 37 | MOBILE_ID = 'MobileId' 38 | USER_ID = 'UserId' 39 | FIRST_NAME = 'FirstName' 40 | LAST_NAME = 'LastName' 41 | COUNTRY_CODE = 'CountryCode' 42 | ZIP_CODE = 'ZipCode' 43 | LIST_NAME = 'List' 44 | 45 | # Default Values 46 | GENERIC_LIST = 'Generic List from the API' 47 | CSV_FILE_PATH = 'audience.csv' 48 | CONFIG_PATH = './googleads_config.yaml' 49 | MEMBERSHIP_LIFESPAN_DAYS = 8 50 | 51 | # Constants 52 | CONTACT_INFO = 'CONTACT_INFO' 53 | MOBILE_ADVERTISING_ID = 'MOBILE_ADVERTISING_ID' 54 | CRM_ID = 'CRM_ID' 55 | 56 | 57 | def generate_list_data_base(list_type): 58 | """Generates an empty customer list data object. 59 | 60 | Args: 61 | list_type: The type of customer list (based on CustomerMatchUploadKeyType). 62 | 63 | Returns: 64 | data_base: an empty customer list data object. 65 | """ 66 | data_base = {} 67 | if list_type == CONTACT_INFO: 68 | data_base['emails'] = [] 69 | data_base['phones'] = [] 70 | data_base['addresses'] = [] 71 | elif list_type == MOBILE_ADVERTISING_ID: 72 | data_base['mobile_ids'] = [] 73 | elif list_type == CRM_ID: 74 | data_base['user_ids'] = [] 75 | return data_base 76 | 77 | 78 | def is_list_empty(customer_data): 79 | if customer_data: 80 | for item in customer_data: 81 | if customer_data[item]: 82 | return False 83 | return True 84 | 85 | 86 | def read_csv(path, list_type, hash_required): 87 | """Reads customer data from CSV and stores it in memory. 88 | 89 | Args: 90 | path: CSV file path. 91 | list_type: The type of customer list (based on CustomerMatchUploadKeyType). 92 | hash_required: Indicates if the customer data needs to be hashed. 93 | 94 | Returns: 95 | customer_data: Processed data from CSV. 96 | """ 97 | with open(path, mode='r') as csv_file: 98 | csv_reader = csv.DictReader(csv_file) 99 | line_count = 0 100 | 101 | customer_data = {} 102 | 103 | for row in csv_reader: 104 | if HEADER_LINE and line_count == 0: 105 | # Skip Header Line 106 | line_count += 1 107 | next # pylint: disable=pointless-statement 108 | 109 | if row.get(LIST_NAME): 110 | if not customer_data.get(row[LIST_NAME]): 111 | customer_data[row[LIST_NAME]] = generate_list_data_base(list_type) 112 | list_data = customer_data[row[LIST_NAME]] 113 | else: 114 | # Use generic list 115 | if not customer_data.get(GENERIC_LIST): 116 | customer_data[GENERIC_LIST] = generate_list_data_base(list_type) 117 | list_data = customer_data[GENERIC_LIST] 118 | if list_type == CONTACT_INFO: 119 | if row.get(EMAIL): 120 | if hash_required: 121 | list_data['emails'].append( 122 | {'hashed_email': normalize_and_sha256(row[EMAIL])}) 123 | else: 124 | list_data['emails'].append({'hashed_email': row[EMAIL]}) 125 | 126 | if row.get(PHONE): 127 | if hash_required: 128 | list_data['phones'].append( 129 | {'hashed_phone_number': normalize_and_sha256(row[PHONE])}) 130 | else: 131 | list_data['phones'].append({'hashed_phone_number': row[PHONE]}) 132 | 133 | if (row.get(FIRST_NAME) and row.get(LAST_NAME) and 134 | row.get(COUNTRY_CODE) and row.get(ZIP_CODE)): 135 | address = {} 136 | if hash_required: 137 | address['hashed_first_name'] = normalize_and_sha256(row[FIRST_NAME]) 138 | address['hashed_last_name'] = normalize_and_sha256(row[LAST_NAME]) 139 | else: 140 | address['hashed_first_name'] = row[FIRST_NAME] 141 | address['hashed_last_name'] = row[LAST_NAME] 142 | address['country_code'] = row[COUNTRY_CODE] 143 | address['zip_code'] = row[ZIP_CODE] 144 | list_data['addresses'].append(address) 145 | 146 | elif list_type == MOBILE_ADVERTISING_ID: 147 | if row.get(MOBILE_ID): 148 | list_data['mobile_ids'].append({'mobile_id': row[MOBILE_ID]}) 149 | 150 | elif list_type == CRM_ID: 151 | if row.get(USER_ID): 152 | list_data['user_ids'].append({'third_party_user_id': row[USER_ID]}) 153 | line_count += 1 154 | 155 | print(f'Processed {line_count} lines from file {path}.') 156 | 157 | return customer_data 158 | 159 | 160 | def get_user_list_resource_name(client, customer_id, list_name): 161 | """Gets the User List using the name provided. 162 | 163 | Args: 164 | client: The Google Ads client instance. 165 | customer_id: The customer ID for which to add the user list. 166 | list_name: The name of the user list to search. 167 | 168 | Returns: 169 | The User List resource name. 170 | """ 171 | googleads_service_client = client.get_service('GoogleAdsService') 172 | query = f''' 173 | SELECT 174 | user_list.id, 175 | user_list.name 176 | FROM user_list 177 | WHERE user_list.name = '{list_name}' 178 | ''' 179 | 180 | search_results = googleads_service_client.search( 181 | customer_id=customer_id, query=query) 182 | 183 | user_list_resource_name = None 184 | for result in search_results: 185 | user_list_resource_name = result.user_list.resource_name 186 | 187 | return user_list_resource_name 188 | 189 | 190 | def create_user_list(client, customer_id, list_name, list_type, app_id=None): 191 | """Creates a User List using the name provided. 192 | 193 | Args: 194 | client: The Google Ads client instance. 195 | customer_id: The customer ID for which to add the user list. 196 | list_name: The name of the user list to search. 197 | list_type: The type of customer list (based on CustomerMatchUploadKeyType). 198 | app_id: App ID required only for mobile advertising lists. 199 | 200 | Returns: 201 | The User List resource name. 202 | """ 203 | print(f'The user list {list_name} will be created.') 204 | user_list_service_client = client.get_service('UserListService') 205 | user_list_operation = client.get_type('UserListOperation') 206 | 207 | # Creates the new user list. 208 | user_list = user_list_operation.create 209 | user_list.name = list_name 210 | user_list.description = ('This is a list of users uploaded using Ads API.') 211 | user_list.crm_based_user_list.upload_key_type = ( 212 | customer_match_upload_key_type.CustomerMatchUploadKeyTypeEnum.CustomerMatchUploadKeyType[list_type]) 213 | if list_type == MOBILE_ADVERTISING_ID: 214 | user_list.crm_based_user_list.app_id = app_id 215 | 216 | user_list.membership_life_span = MEMBERSHIP_LIFESPAN_DAYS 217 | 218 | response = user_list_service_client.mutate_user_lists( 219 | customer_id=customer_id, operations=[user_list_operation]) 220 | user_list_resource_name = response.results[0].resource_name 221 | print( 222 | f'User list with resource name "{user_list_resource_name}" was created.') 223 | return user_list_resource_name 224 | 225 | 226 | def add_users_to_customer_match_user_list(client, customer_id, 227 | user_list_resource_name, 228 | customer_data, skip_polling): 229 | """Uses Customer Match to create and add users to a new user list. 230 | 231 | Args: 232 | client: The Google Ads client. 233 | customer_id: The customer ID for which to add the user list. 234 | user_list_resource_name: The resource name of the user list to which to 235 | add users. 236 | customer_data: Processed customer data to be uploaded. 237 | skip_polling: A bool dictating whether to poll the API for completion. 238 | """ 239 | 240 | offline_user_data_job_service_client = client.get_service( 241 | 'OfflineUserDataJobService') 242 | 243 | offline_user_data_job = client.get_type('OfflineUserDataJob') 244 | offline_user_data_job.type_ = client.get_type( 245 | 'OfflineUserDataJobTypeEnum' 246 | ).OfflineUserDataJobType.CUSTOMER_MATCH_USER_LIST 247 | offline_user_data_job.customer_match_user_list_metadata.user_list = ( 248 | user_list_resource_name) 249 | 250 | # Issues a request to create an offline user data job. 251 | create_offline_user_data_job_response = ( 252 | offline_user_data_job_service_client.create_offline_user_data_job( 253 | customer_id=customer_id, job=offline_user_data_job)) 254 | offline_user_data_job_resource_name = ( 255 | create_offline_user_data_job_response.resource_name) 256 | print('Created an offline user data job with resource name: ' 257 | f'"{offline_user_data_job_resource_name}".') 258 | 259 | request = client.get_type('AddOfflineUserDataJobOperationsRequest') 260 | request.resource_name = offline_user_data_job_resource_name 261 | request.operations.extend(build_offline_user_data_job_operations( 262 | client, customer_data)) 263 | request.enable_partial_failure = True 264 | 265 | # Issues a request to add the operations to the offline user data job. 266 | response = offline_user_data_job_service_client.add_offline_user_data_job_operations( 267 | request=request) 268 | 269 | # Prints the status message if any partial failure error is returned. 270 | # Note: the details of each partial failure error are not printed here. 271 | # Refer to the error_handling/handle_partial_failure.py example to learn 272 | # more. 273 | # Extracts the partial failure from the response status. 274 | partial_failure = getattr(response, 'partial_failure_error', None) 275 | if getattr(partial_failure, 'code', None) != 0: 276 | error_details = getattr(partial_failure, 'details', []) 277 | for error_detail in error_details: 278 | failure_message = client.get_type('GoogleAdsFailure') 279 | # Retrieve the class definition of the GoogleAdsFailure instance 280 | # in order to use the "deserialize" class method to parse the 281 | # error_detail string into a protobuf message object. 282 | failure_object = type(failure_message).deserialize(error_detail.value) 283 | 284 | for error in failure_object.errors: 285 | print('A partial failure at index ' 286 | f'{error.location.field_path_elements[0].index} occurred.\n' 287 | f'Error message: {error.message}\n' 288 | f'Error code: {error.error_code}') 289 | 290 | print('The operations are added to the offline user data job.') 291 | 292 | # Issues a request to run the offline user data job for executing all 293 | # added operations. 294 | operation_response = ( 295 | offline_user_data_job_service_client.run_offline_user_data_job( 296 | resource_name=offline_user_data_job_resource_name)) 297 | 298 | if skip_polling: 299 | check_job_status( 300 | client, 301 | customer_id, 302 | offline_user_data_job_resource_name, 303 | user_list_resource_name, 304 | ) 305 | else: 306 | # Wait until the operation has finished. 307 | print('Request to execute the added operations started.') 308 | print('Waiting until operation completes...') 309 | operation_response.result() 310 | print_customer_match_user_list_info(client, customer_id, 311 | user_list_resource_name) 312 | 313 | 314 | def build_offline_user_data_job_operations(client, customer_data): 315 | """Builds the schema of user data as defined in the API. 316 | 317 | Args: 318 | client: The Google Ads client. 319 | customer_data: Processed customer data to be uploaded. 320 | 321 | Returns: 322 | A list containing the operations. 323 | """ 324 | 325 | customer_data_operations = [] 326 | 327 | for data_type in customer_data: 328 | for item in customer_data[data_type]: 329 | # Creates a first user data based on an email address. 330 | user_data_operation = client.get_type('OfflineUserDataJobOperation') 331 | user_data = user_data_operation.create 332 | user_identifier = client.get_type('UserIdentifier') 333 | 334 | if data_type == 'emails': 335 | user_identifier.hashed_email = item['hashed_email'] 336 | elif data_type == 'phones': 337 | user_identifier.hashed_phone_number = item['hashed_phone_number'] 338 | elif data_type == 'mobile_ids': 339 | user_identifier.mobile_id = item['mobile_id'] 340 | elif data_type == 'user_ids': 341 | user_identifier.third_party_user_id = item['third_party_user_id'] 342 | elif data_type == 'addresses': 343 | user_identifier.address_info.hashed_first_name = item[ 344 | 'hashed_first_name'] 345 | user_identifier.address_info.hashed_last_name = item['hashed_last_name'] 346 | user_identifier.address_info.country_code = item['country_code'] 347 | user_identifier.address_info.postal_code = item['postal_code'] 348 | user_data.user_identifiers.append(user_identifier) 349 | 350 | customer_data_operations.append(user_data_operation) 351 | 352 | return customer_data_operations 353 | 354 | 355 | def check_job_status( 356 | client, 357 | customer_id, 358 | offline_user_data_job_resource_name, 359 | user_list_resource_name, 360 | ): 361 | """Retrieves, checks, and prints the status of the offline user data job. 362 | 363 | Args: 364 | client: The Google Ads client. 365 | customer_id: The customer ID for which to add the user list. 366 | offline_user_data_job_resource_name: The resource name of the offline 367 | user data job to get the status of. 368 | user_list_resource_name: The resource name of the customer match user 369 | list 370 | """ 371 | query = f''' 372 | SELECT 373 | offline_user_data_job.resource_name, 374 | offline_user_data_job.id, 375 | offline_user_data_job.status, 376 | offline_user_data_job.type, 377 | offline_user_data_job.failure_reason 378 | FROM offline_user_data_job 379 | WHERE offline_user_data_job.resource_name = 380 | '{offline_user_data_job_resource_name}' 381 | LIMIT 1''' 382 | 383 | # Issues a search request using streaming. 384 | google_ads_service = client.get_service('GoogleAdsService') 385 | results = google_ads_service.search(customer_id=customer_id, query=query) 386 | offline_user_data_job = next(iter(results)).offline_user_data_job 387 | job_type_enum = offline_user_data_job_type.OfflineUserDataJobTypeEnum.OfflineUserDataJobType( 388 | offline_user_data_job.type_) 389 | status_name_enum = offline_user_data_job_status.OfflineUserDataJobStatusEnum.OfflineUserDataJobStatus( 390 | offline_user_data_job.status) 391 | status_name = status_name_enum.name 392 | 393 | print(f'Offline user data job ID \'{offline_user_data_job.id}\' with type ' 394 | f'\'{job_type_enum.name}\' has status: {status_name}') 395 | 396 | if status_name == 'SUCCESS': 397 | print_customer_match_user_list_info(client, customer_id, 398 | user_list_resource_name) 399 | elif status_name == 'FAILED': 400 | print(f'\tFailure Reason: {offline_user_data_job.failure_reason}') 401 | elif status_name in ('PENDING', 'RUNNING'): 402 | print('To check the status of the job periodically, use the following ' 403 | f'GAQL query with GoogleAdsService.Search: {query}') 404 | print('Or you can use the check_job.py script with the following args:') 405 | print(f'\npython check_job.py --config_file {args.config_file} ' 406 | f'--customer_id {customer_id} ' 407 | f'--job_resource_name {offline_user_data_job_resource_name} ' 408 | f'--user_list_resource_name {user_list_resource_name} ') 409 | 410 | 411 | def print_customer_match_user_list_info(client, customer_id, 412 | user_list_resource_name): 413 | """Prints information about the Customer Match user list. 414 | 415 | Args: 416 | client: The Google Ads client. 417 | customer_id: The customer ID for which to add the user list. 418 | user_list_resource_name: The resource name of the user list to which to 419 | add users. 420 | """ 421 | googleads_service_client = client.get_service('GoogleAdsService') 422 | 423 | # Creates a query that retrieves the user list. 424 | query = f''' 425 | SELECT 426 | user_list.size_for_display, 427 | user_list.size_for_search 428 | FROM user_list 429 | WHERE user_list.resource_name = '{user_list_resource_name}' 430 | ''' 431 | 432 | # Issues a search request. 433 | search_results = googleads_service_client.search( 434 | customer_id=customer_id, query=query) 435 | 436 | # Prints out some information about the user list. 437 | user_list = next(iter(search_results)).user_list 438 | print('The estimated number of users that the user list ' 439 | f'\'{user_list.resource_name}\' has is ' 440 | f'{user_list.size_for_display} for Display and ' 441 | f'{user_list.size_for_search} for Search.') 442 | print('Reminder: It may take several hours for the user list to be ' 443 | 'populated. Estimates of size zero are possible.') 444 | 445 | 446 | def upload_data(client, 447 | customer_id, 448 | list_name, 449 | list_type, 450 | customer_data, 451 | skip_polling, 452 | app_id=None): 453 | """Uploads processed data to the specified list and creates it if necessary. 454 | 455 | Args: 456 | client: The Google Ads client. 457 | customer_id: The customer ID for which to add the user list. 458 | list_name: The name of the user list to modify. 459 | list_type: The type of customer list (based on CustomerMatchUploadKeyType). 460 | customer_data: Processed customer data to be uploaded. 461 | skip_polling: A bool dictating whether to poll the API for completion. 462 | app_id: App ID required only for mobile advertising lists. 463 | 464 | Returns: 465 | None. 466 | """ 467 | 468 | user_list_resource_name = get_user_list_resource_name(client, customer_id, 469 | list_name) 470 | 471 | if not user_list_resource_name: 472 | # Create missing user list 473 | user_list_resource_name = create_user_list(client, customer_id, list_name, 474 | list_type, app_id) 475 | 476 | print(f'Uploading data for list \'{list_name}\'') 477 | add_users_to_customer_match_user_list(client, customer_id, 478 | user_list_resource_name, customer_data, 479 | skip_polling) 480 | 481 | 482 | def normalize_and_sha256(s): 483 | """Normalizes (lowercase, remove whitespace) and hashes a string with SHA-256. 484 | 485 | Args: 486 | s: The string to perform this operation on. 487 | 488 | Returns: 489 | A normalized and SHA-256 hashed string. 490 | """ 491 | return hashlib.sha256(s.strip().lower().encode()).hexdigest() 492 | 493 | 494 | if __name__ == '__main__': 495 | parser = argparse.ArgumentParser( 496 | description='Uploads customer match list to Google Ads.') 497 | parser.add_argument( 498 | '--config_file', 499 | default=CONFIG_PATH, 500 | help='Configuration file for Google Ads API access.') 501 | parser.add_argument( 502 | '--customer_id', 503 | required=True, 504 | help='The customer ID for which to add the user list.') 505 | parser.add_argument( 506 | '--audience_file', 507 | default=CSV_FILE_PATH, 508 | help='CSV file with audience list.') 509 | parser.add_argument( 510 | '--list_type', 511 | default=CONTACT_INFO, 512 | choices=[CONTACT_INFO, MOBILE_ADVERTISING_ID, CRM_ID], 513 | help='Customer match upload key types. Default value: CONTACT_INFO') 514 | parser.add_argument( 515 | '--app_id', 516 | required=False, 517 | default=None, 518 | help=('App ID to associate with the list. Only required for ' 519 | 'Mobile Advertising Lists.')) 520 | parser.add_argument( 521 | '--hash_required', 522 | action='store_true', 523 | default=False, 524 | help='Indicates that the customer data needs to be hashed.') 525 | parser.add_argument( 526 | '--wait', 527 | action='store_true', 528 | default=False, 529 | help='Wait for the jobs to finish (each job will be blocking).') 530 | args = parser.parse_args() 531 | 532 | data = read_csv(args.audience_file, args.list_type, args.hash_required) 533 | 534 | google_ads_client = GoogleAdsClient.load_from_storage(args.config_file) 535 | 536 | for name in data: 537 | print(f'Processing data for list \'{name}\'.') 538 | try: 539 | if not is_list_empty(data[name]): 540 | upload_data(google_ads_client, args.customer_id, name, args.list_type, 541 | data[name], not args.wait, args.app_id) 542 | else: 543 | print(f'The list \'{name}\' will be skipped as no compatible data ' 544 | 'has been found.') 545 | except GoogleAdsException as ex: 546 | print(f'Request with ID "{ex.request_id}" failed with status ' 547 | f'"{ex.error.code().name}" and includes the following errors:') 548 | for single_error in ex.failure.errors: 549 | print(f'\tError with message "{single_error.message}".') 550 | if single_error.location: 551 | for field_path_element in single_error.location.field_path_elements: 552 | print(f'\t\tOn field: {field_path_element.field_name}') 553 | 554 | print('The process has finished.') 555 | -------------------------------------------------------------------------------- /generate_refresh_token.py: -------------------------------------------------------------------------------- 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 | """This example creates an OAuth 2.0 refresh token for the Google Ads API. 16 | 17 | This illustrates how to step through the OAuth 2.0 native / installed 18 | application flow. 19 | 20 | It is intended to be run from the command line and requires user input. 21 | """ 22 | 23 | import argparse 24 | import json 25 | import re 26 | 27 | from google_auth_oauthlib.flow import Flow 28 | 29 | SCOPE = 'https://www.googleapis.com/auth/adwords' 30 | 31 | 32 | def main(client_secrets_path, scopes): 33 | with open(client_secrets_path) as client_secrets_file: 34 | client_secrets = json.load(client_secrets_file) 35 | redirect_uri = client_secrets['installed']['redirect_uris'][0] 36 | flow = Flow.from_client_secrets_file( 37 | client_secrets_path, scopes=scopes, redirect_uri=redirect_uri) 38 | print('Please open this URL in your browser and follow the prompts to ' 39 | 'authorize this script: ' 40 | f'{flow.authorization_url()[0]}') 41 | print(f""" 42 | If there is no local web server serving at {redirect_uri}, the \ 43 | succeeded OAuth flow will land the browser on an error page ("This site \ 44 | can't be reached"). This is an expected behavior. Copy the whole URL and \ 45 | continue. 46 | """) 47 | url = input('Copy the code (or the complete url if no code is shown) ' 48 | 'from the browser and paste it here: ') 49 | code = re.sub(r'&.*$','', re.sub(r'^.*code=', '', url)) 50 | 51 | flow.fetch_token(code=code) 52 | 53 | print('Access token: %s' % flow.credentials.token) 54 | print('Refresh token: %s' % flow.credentials.refresh_token) 55 | 56 | 57 | if __name__ == '__main__': 58 | parser = argparse.ArgumentParser( 59 | description='Generates OAuth 2.0 credentials with the specified ' 60 | 'client secrets file.') 61 | # The following argument(s) should be provided to run the example. 62 | parser.add_argument( 63 | '--client_secrets_path', 64 | required=True, 65 | help=('Path to the client secrets JSON file from the ' 66 | 'Google Developers Console that contains your ' 67 | 'client ID and client secret.'), 68 | ) 69 | parser.add_argument( 70 | '--additional_scopes', 71 | default=None, 72 | help=('Additional scopes to apply when generating the ' 73 | 'refresh token. Each scope should be separated ' 74 | 'by a comma.'), 75 | ) 76 | args = parser.parse_args() 77 | 78 | configured_scopes = [SCOPE] 79 | 80 | if args.additional_scopes: 81 | configured_scopes.extend(args.additional_scopes.replace(' ', '').split(',')) 82 | 83 | main(args.client_secrets_path, configured_scopes) 84 | 85 | -------------------------------------------------------------------------------- /googleads_config.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | login_customer_id: XXXXXXXXXX 15 | 16 | developer_token: XXXXXXXXXXXXXXXXXXXXXX 17 | client_id: XXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.XXXX.XXXXXXXXXXXXXXXXX.XXX 18 | client_secret: XXXXXXXXXXXXXXXXXXXXXXXX 19 | refresh_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 20 | 21 | use_proto_plus: False 22 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | google-ads 2 | -------------------------------------------------------------------------------- /third_party/googleads/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /third_party/oauth2client/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------