# Google Ads Remarketing Export Integration CLI ## Install ‘td’ Command Install the newest [TD Toolbelt](https://toolbelt.treasuredata.com/). ## Create Google OAuth2 Credentials Complete the following steps to create OAuth credentials (`client_id` & `client_secret`): 1. Open Google API Console Credentials: [https://console.developers.google.com/apis/credentials](https://console.developers.google.com/apis/credentials) 2. From the project drop-down (upper left corner), click **New Project**, enter a name for the project, and optionally, edit the provided Project ID. Click **Create**. ![](/assets/image-20191015-160905.caa8b1cce14fbbb9c01caa3b70963985095e89e53e2c9836292726eb4f5a5da7.381d5938.png) 1. On the Credentials page, Create credentials tab, select **OAuth client ID**. 2. You may be prompted to set a product name on the Consent screen; if so, select **Configure consent screen,** supply the requested information, and click **Save** to return to the Credentials screen. 3. Select "Web Application" for the Application Type. Provide a name for your OAuth credentials. Make sure that you add the Google OAuth playground URL to "Authorized redirect URIs": ``` https://developers.google.com/oauthplayground ``` ![](/assets/image-20191015-160917.c527c0b2f63ed9eab48d2decc1395086c4920fc2292223e959db3a620f2a2fd0.381d5938.png) 1. Select **Create**. 2. Copy the client ID and client secret to your clipboard. You will need the information when you configure your connector job. ![](/assets/image-20191015-160925.b9931ce15fa920878c8811651e735d917c808063fa76ca0f24488604939e513b.381d5938.png) See more [information on Google credentialing](https://developers.google.com/adwords/api/docs/guides/authentication#webapp). ## Authorize Ads Account to OAuth Credentials You can use Google OAuth Playground to generate `refresh_token` from OAuth credentials. This process is to authorize your OAuth app, to access your Ads account. 1. Go to: [https://developers.google.com/oauthplayground](https://developers.google.com/oauthplayground) 2. Select **Settings** in the upper right corner and check **Use your own OAuth credentials.** 3. Input "OAuth Client ID" & "OAuth Client Secret" from the preceding section 4. Input required scopes (OAuth2 permissions) with: ``` https://www.googleapis.com/auth/adwords https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email ``` ![](/assets/image-20191015-160940.bc3fc4fddf91450a594060edc259a955458f58daee8f51806d515370c76a8b87.381d5938.png) 1. Select **Authorize APIs** and login to your Google Ads account. 2. You are redirected back to OAuth2 Playground, select **Exchange authorization codes for tokens.** ![](/assets/image-20191015-160952.f30746ee731818a9d52d272f96540aaf935a9cd5296e0d9dcfad3ec212819438.381d5938.png) ## Prepare Query Command Add the Google Ads Remarketing result output destination by using the `-r` / `--result` option for the `td query` command: ``` $ td query -d mydb 'SELECT email FROM app_users' -r '{"type":"google_adwords","client_id":"773#######################################j33.apps.googleusercontent.com","client_secret":"A######################N","developer_token":"9####################Q","refresh_token":"1/CG#######################################KI","client_customer_id":"111-222-3333","name":"abc_app_user_list","description":"User list from mobile app abc","app_id":"abc","mode":"append","membership_lifespan":10000,"batch_size":100000,"maximum_retries":5,"initial_retry_interval_millis":500,"maximum_retry_interval_millis":300000}' ``` Where: - `client_id`: (required) Your Google OAuth2 credentials - `client_secret`: (required) Your Google OAuth2 credentials - `refresh_token`: (required) Your Google OAuth2 credentials - `developer_token`: (required) Your Google Ads Developer Token - `client_customer_id`: (required) Your Google Ads Customer ID. Format: `nnn-nnn-nnnn` where `n` is a digit. - `name`: (required) Name of the user list - `description`: (optional) Description of the user list. Default: *empty.* - `app_id`: Mobile Application ID (only required for `mobile_id` export) - `mode`: (optional) Upload mode. Default: append. Supported values: - `append` - `replace` - `remove` - `membership_lifespan`: (optional) Number of days users' contact info stays on the user list. Default: `10000`. - `batch_size`: (optional) Number of records to upload in each batch. Default: `100000.` - `maximum_retries`: (optional) Number of retries before system gives up. Default: `5.` - `initial_retry_interval_millis`: (optional) Initial retry time wait in milliseconds. Default: `500`, which is equivalent to 0.5 seconds. - `maximum_retry_interval_millis`: (optional) Max retry wait in milliseconds. Default: `300000`, which is equivalent to 5 minutes.