From bcb2a4c7d27a9c1df0d56829c8583574189990ac Mon Sep 17 00:00:00 2001 From: Lindsey Volta Date: Mon, 16 Mar 2026 15:03:42 -0700 Subject: [PATCH] Remove Python v4 code samples following sunset. PiperOrigin-RevId: 884653453 --- python/v4/README.md | 40 ----- python/v4/__init__.py | 15 -- .../assign_advertiser_to_advertiser_group.py | 74 -------- python/v4/assign_creative_to_campaign.py | 74 -------- .../v4/authenticate_using_service_account.py | 102 ----------- python/v4/authenticate_using_user_account.py | 100 ----------- python/v4/client_secrets.json | 9 - .../v4/configure_dynamic_asset_selection.py | 144 ---------------- python/v4/create_advertiser.py | 63 ------- python/v4/create_advertiser_group.py | 62 ------- python/v4/create_advertiser_landing_page.py | 72 -------- python/v4/create_campaign.py | 91 ---------- python/v4/create_campaign_event_tag.py | 69 -------- python/v4/create_content_category.py | 62 ------- python/v4/create_creative_field.py | 70 -------- python/v4/create_creative_field_value.py | 69 -------- python/v4/create_creative_group.py | 72 -------- .../create_display_image_gallery_creative.py | 139 --------------- python/v4/create_display_redirect_creative.py | 80 --------- python/v4/create_floodlight_activity.py | 73 -------- python/v4/create_floodlight_activity_group.py | 71 -------- python/v4/create_html5_display_creative.py | 150 ----------------- python/v4/create_image_display_creative.py | 118 ------------- python/v4/create_instream_audio_creative.py | 110 ------------ python/v4/create_instream_video_creative.py | 110 ------------ python/v4/create_placement.py | 94 ----------- python/v4/create_placement_group.py | 87 ---------- python/v4/create_placement_strategy.py | 62 ------- python/v4/create_remarketing_list.py | 96 ----------- python/v4/create_report.py | 158 ------------------ python/v4/create_rotation_group.py | 114 ------------- python/v4/create_subaccount.py | 76 --------- python/v4/create_targeting_template.py | 79 --------- python/v4/create_tracking_creative.py | 67 -------- python/v4/create_user_role.py | 75 --------- python/v4/delete_report.py | 60 ------- python/v4/dfareporting_utils.py | 132 --------------- python/v4/download_file.py | 91 ---------- python/v4/download_floodlight_tag.py | 70 -------- python/v4/download_placement_tags.py | 82 --------- python/v4/find_and_download_file.py | 149 ----------------- python/v4/find_and_run_report.py | 147 ---------------- python/v4/get_ads.py | 66 -------- python/v4/get_advertiser_groups.py | 64 ------- python/v4/get_advertiser_landing_pages.py | 71 -------- python/v4/get_advertisers.py | 67 -------- python/v4/get_campaigns.py | 64 ------- python/v4/get_change_logs_for_advertiser.py | 76 --------- python/v4/get_compatible_fields.py | 87 ---------- python/v4/get_content_categories.py | 64 ------- python/v4/get_creative_field_values.py | 69 -------- python/v4/get_creative_fields.py | 64 ------- python/v4/get_creative_groups.py | 64 ------- python/v4/get_creatives.py | 72 -------- python/v4/get_dimension_values.py | 72 -------- python/v4/get_files.py | 64 ------- python/v4/get_floodlight_activities.py | 72 -------- python/v4/get_floodlight_activity_groups.py | 66 -------- python/v4/get_placement_strategies.py | 64 ------- python/v4/get_placements.py | 65 ------- python/v4/get_remarketing_lists.py | 75 --------- python/v4/get_report_files.py | 69 -------- python/v4/get_reports.py | 63 ------- python/v4/get_sites.py | 64 ------- python/v4/get_size.py | 66 -------- python/v4/get_subaccounts.py | 69 -------- python/v4/get_targeting_templates.py | 72 -------- python/v4/get_user_role_permissions.py | 72 -------- python/v4/get_user_roles.py | 70 -------- python/v4/get_userprofiles.py | 50 ------ python/v4/insert_offline_mobile_conversion.py | 90 ---------- python/v4/insert_offline_user_conversion.py | 112 ------------- python/v4/run_report.py | 97 ----------- .../share_remarketing_list_to_advertiser.py | 75 --------- python/v4/target_ad_to_remarketing_list.py | 77 --------- python/v4/update_offline_mobile_conversion.py | 116 ------------- python/v4/update_offline_user_conversion.py | 140 ---------------- 77 files changed, 6286 deletions(-) delete mode 100644 python/v4/README.md delete mode 100644 python/v4/__init__.py delete mode 100755 python/v4/assign_advertiser_to_advertiser_group.py delete mode 100755 python/v4/assign_creative_to_campaign.py delete mode 100644 python/v4/authenticate_using_service_account.py delete mode 100644 python/v4/authenticate_using_user_account.py delete mode 100644 python/v4/client_secrets.json delete mode 100644 python/v4/configure_dynamic_asset_selection.py delete mode 100755 python/v4/create_advertiser.py delete mode 100755 python/v4/create_advertiser_group.py delete mode 100755 python/v4/create_advertiser_landing_page.py delete mode 100755 python/v4/create_campaign.py delete mode 100755 python/v4/create_campaign_event_tag.py delete mode 100755 python/v4/create_content_category.py delete mode 100644 python/v4/create_creative_field.py delete mode 100644 python/v4/create_creative_field_value.py delete mode 100644 python/v4/create_creative_group.py delete mode 100755 python/v4/create_display_image_gallery_creative.py delete mode 100755 python/v4/create_display_redirect_creative.py delete mode 100755 python/v4/create_floodlight_activity.py delete mode 100755 python/v4/create_floodlight_activity_group.py delete mode 100755 python/v4/create_html5_display_creative.py delete mode 100755 python/v4/create_image_display_creative.py delete mode 100755 python/v4/create_instream_audio_creative.py delete mode 100755 python/v4/create_instream_video_creative.py delete mode 100755 python/v4/create_placement.py delete mode 100755 python/v4/create_placement_group.py delete mode 100755 python/v4/create_placement_strategy.py delete mode 100644 python/v4/create_remarketing_list.py delete mode 100644 python/v4/create_report.py delete mode 100644 python/v4/create_rotation_group.py delete mode 100755 python/v4/create_subaccount.py delete mode 100644 python/v4/create_targeting_template.py delete mode 100755 python/v4/create_tracking_creative.py delete mode 100755 python/v4/create_user_role.py delete mode 100644 python/v4/delete_report.py delete mode 100644 python/v4/dfareporting_utils.py delete mode 100644 python/v4/download_file.py delete mode 100644 python/v4/download_floodlight_tag.py delete mode 100644 python/v4/download_placement_tags.py delete mode 100644 python/v4/find_and_download_file.py delete mode 100644 python/v4/find_and_run_report.py delete mode 100755 python/v4/get_ads.py delete mode 100644 python/v4/get_advertiser_groups.py delete mode 100644 python/v4/get_advertiser_landing_pages.py delete mode 100755 python/v4/get_advertisers.py delete mode 100644 python/v4/get_campaigns.py delete mode 100644 python/v4/get_change_logs_for_advertiser.py delete mode 100644 python/v4/get_compatible_fields.py delete mode 100644 python/v4/get_content_categories.py delete mode 100644 python/v4/get_creative_field_values.py delete mode 100644 python/v4/get_creative_fields.py delete mode 100644 python/v4/get_creative_groups.py delete mode 100644 python/v4/get_creatives.py delete mode 100644 python/v4/get_dimension_values.py delete mode 100644 python/v4/get_files.py delete mode 100644 python/v4/get_floodlight_activities.py delete mode 100644 python/v4/get_floodlight_activity_groups.py delete mode 100644 python/v4/get_placement_strategies.py delete mode 100644 python/v4/get_placements.py delete mode 100644 python/v4/get_remarketing_lists.py delete mode 100644 python/v4/get_report_files.py delete mode 100644 python/v4/get_reports.py delete mode 100644 python/v4/get_sites.py delete mode 100644 python/v4/get_size.py delete mode 100644 python/v4/get_subaccounts.py delete mode 100644 python/v4/get_targeting_templates.py delete mode 100644 python/v4/get_user_role_permissions.py delete mode 100644 python/v4/get_user_roles.py delete mode 100644 python/v4/get_userprofiles.py delete mode 100644 python/v4/insert_offline_mobile_conversion.py delete mode 100644 python/v4/insert_offline_user_conversion.py delete mode 100644 python/v4/run_report.py delete mode 100644 python/v4/share_remarketing_list_to_advertiser.py delete mode 100644 python/v4/target_ad_to_remarketing_list.py delete mode 100644 python/v4/update_offline_mobile_conversion.py delete mode 100644 python/v4/update_offline_user_conversion.py diff --git a/python/v4/README.md b/python/v4/README.md deleted file mode 100644 index be20287..0000000 --- a/python/v4/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# DFA Reporting and Trafficking Python Samples - -This is a collection of samples written in Python which provide a starting place -for your experimentation into the DFA Reporting and Trafficking API. - -## Prerequisites - -Please make sure that you're running the latest version of Python 2 and have pip -installed. Use the following command from the samples directory to install all -dependencies: - -```Batchfile -$ pip install --upgrade google-api-python-client -``` - -## Setup Authentication - -This API uses OAuth 2.0. Learn more about Google APIs and OAuth 2.0 here: -https://developers.google.com/accounts/docs/OAuth2 - -Or, if you'd like to dive right in, follow these steps. - - Visit https://console.developers.google.com to register your application. - - From the API Manager -> Google APIs screen, activate access to "DCM/DFA Reporting and Trafficking API". - - Click on "Credentials" in the left navigation menu - - Click the button labeled "Create credentials" and select "OAuth Client ID" - - Select "Other" as the "Application type", then "Create" - - From the Credentials page, click "Download JSON" next to the client ID you just created and save the file as `client_secrets.json` in the samples project directory - -## Running the Examples - -I'm assuming you've checked out the code and are reading this from a local -directory. If not check out the code to a local directory. - -1. Start up a sample, e.g. - - $ python create_report.py - -2. Complete the authorization steps on your browser - -3. Examine your shell output, be inspired and start hacking an amazing new app! diff --git a/python/v4/__init__.py b/python/v4/__init__.py deleted file mode 100644 index f9fabef..0000000 --- a/python/v4/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Code samples for the DCM/DFA Reporting and Trafficking API.""" diff --git a/python/v4/assign_advertiser_to_advertiser_group.py b/python/v4/assign_advertiser_to_advertiser_group.py deleted file mode 100755 index c9a66fa..0000000 --- a/python/v4/assign_advertiser_to_advertiser_group.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example assigns an advertiser to an advertiser group. - -CAUTION: An advertiser that has campaigns associated with it cannot be -removed from an advertiser group once assigned. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add advertiser groups for') -argparser.add_argument( - 'advertiser_group_id', type=int, - help='The ID of the advertiser group to add to') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to add') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_group_id = flags.advertiser_group_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - advertiser = { - 'advertiserGroupId': advertiser_group_id - } - - request = service.advertisers().patch( - profileId=profile_id, id=advertiser_id, body=advertiser) - - # Execute request and print response. - response = request.execute() - - print ('Assigned advertiser with ID %s to advertiser group with ID %s.' - % (response['id'], response['advertiserGroupId'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/assign_creative_to_campaign.py b/python/v4/assign_creative_to_campaign.py deleted file mode 100755 index 940565e..0000000 --- a/python/v4/assign_creative_to_campaign.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example assigns a given creative to a given campaign. - -Note that both the creative and campaign must be associated with the same -advertiser. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to create this association as') -argparser.add_argument( - 'campaign_id', type=int, - help='The ID of the campaign to associate the creative with') -argparser.add_argument( - 'creative_id', type=int, - help='The ID of the creative to be associated') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - campaign_id = flags.campaign_id - creative_id = flags.creative_id - - try: - # Construct the request. - association = { - 'creativeId': creative_id - } - - request = service.campaignCreativeAssociations().insert( - profileId=profile_id, campaignId=campaign_id, body=association) - - # Execute request and print response. - response = request.execute() - - print ('Creative with ID %s is now associated with campaign %s.' - % (response['creativeId'], campaign_id)) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/authenticate_using_service_account.py b/python/v4/authenticate_using_service_account.py deleted file mode 100644 index 11bf24f..0000000 --- a/python/v4/authenticate_using_service_account.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example demonstrates how to authenticate using a service account. - -An optional Google account email to impersonate may be specified as follows: - authenticate_using_service_account.py -i - -This optional flag only applies to service accounts which have domain-wide -delegation enabled and wish to make API requests on behalf of an account -within that domain. Using this flag will not allow you to impersonate a -user from a domain you don't own (e.g., gmail.com). -""" - -import argparse -import sys - -from googleapiclient import discovery -import httplib2 -from oauth2client import client -from oauth2client import tools -from oauth2client.service_account import ServiceAccountCredentials - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'path_to_service_account_json_file', - help='Path to the service account JSON file to use for authenticating.') -argparser.add_argument( - '-i', - '--impersonation_email', - help='Google account email to impersonate.') - -# The OAuth 2.0 scopes to request. -OAUTH_SCOPES = ['https://www.googleapis.com/auth/dfareporting'] - - -def main(argv): - # Retrieve command line arguments. - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, - parents=[tools.argparser, argparser]) - flags = parser.parse_args(argv[1:]) - - # Authenticate using the supplied service account credentials - http = authenticate_using_service_account( - flags.path_to_service_account_json_file, - flags.impersonation_email) - - # Construct a service object via the discovery service. - service = discovery.build('dfareporting', 'v4', http=http) - - try: - # Construct the request. - request = service.userProfiles().list() - - # Execute request and print response. - response = request.execute() - - for profile in response['items']: - print('Found user profile with ID %s and user name "%s".' % - (profile['profileId'], profile['userName'])) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def authenticate_using_service_account(path_to_service_account_json_file, - impersonation_email): - """Authorizes an httplib2.Http instance using service account credentials.""" - # Load the service account credentials from the specified JSON keyfile. - credentials = ServiceAccountCredentials.from_json_keyfile_name( - path_to_service_account_json_file, - scopes=OAUTH_SCOPES) - - # Configure impersonation (if applicable). - if impersonation_email: - credentials = credentials.create_delegated(impersonation_email) - - # Use the credentials to authorize an httplib2.Http instance. - http = credentials.authorize(httplib2.Http()) - - return http - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/authenticate_using_user_account.py b/python/v4/authenticate_using_user_account.py deleted file mode 100644 index 0daebca..0000000 --- a/python/v4/authenticate_using_user_account.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2017 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example demonstrates how to authenticate using a user account. - -Utilizes the OAuth 2.0 installed application flow. -""" - -import argparse -import sys - -from googleapiclient import discovery -import httplib2 -from oauth2client import client -from oauth2client import tools -from oauth2client.file import Storage - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'path_to_client_secrets_file', - help='Path to the client_secrets.json file to use for authenticating.') - -# Filename used for the credential store. -CREDENTIAL_STORE_FILE = 'auth-sample.dat' - -# The OAuth 2.0 scopes to request. -OAUTH_SCOPES = ['https://www.googleapis.com/auth/dfareporting'] - - -def main(argv): - # Retrieve command line arguments. - parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter, - parents=[tools.argparser, argparser]) - flags = parser.parse_args(argv[1:]) - - # Authenticate using the supplied user account credentials - http = authenticate_using_user_account(flags.path_to_client_secrets_file) - - # Construct a service object via the discovery service. - service = discovery.build('dfareporting', 'v4', http=http) - - try: - # Construct the request. - request = service.userProfiles().list() - - # Execute request and print response. - response = request.execute() - - for profile in response['items']: - print('Found user profile with ID %s and user name "%s".' % - (profile['profileId'], profile['userName'])) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def authenticate_using_user_account(path_to_client_secrets_file): - """Authorizes an httplib2.Http instance using user account credentials.""" - # Set up a Flow object to be used if we need to authenticate. - flow = client.flow_from_clientsecrets( - path_to_client_secrets_file, scope=OAUTH_SCOPES) - - # Check whether credentials exist in the credential store. Using a credential - # store allows auth credentials to be cached, so they survive multiple runs - # of the application. This avoids prompting the user for authorization every - # time the access token expires, by remembering the refresh token. - storage = Storage(CREDENTIAL_STORE_FILE) - credentials = storage.get() - - # If no credentials were found, go through the authorization process and - # persist credentials to the credential store. - if credentials is None or credentials.invalid: - credentials = tools.run_flow(flow, storage, - tools.argparser.parse_known_args()[0]) - - # Use the credentials to authorize an httplib2.Http instance. - http = credentials.authorize(httplib2.Http()) - - return http - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/client_secrets.json b/python/v4/client_secrets.json deleted file mode 100644 index d862697..0000000 --- a/python/v4/client_secrets.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "installed": { - "client_id": "[[INSERT YOUR CLIENT ID HERE]]", - "client_secret": "[[INSERT YOUR CLIENT SECRET HERE]]", - "redirect_uris": [], - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://accounts.google.com/o/oauth2/token" - } -} diff --git a/python/v4/configure_dynamic_asset_selection.py b/python/v4/configure_dynamic_asset_selection.py deleted file mode 100644 index 5c3ec29..0000000 --- a/python/v4/configure_dynamic_asset_selection.py +++ /dev/null @@ -1,144 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example enables dynamic asset selection for an in-stream video creative. - -Requires an existing in-stream video creative, a new video asset, and a -targeting template ID as input. To get an in-stream video creative, run -create_instream_video_creative.py. To get a targeting template, run -create_targeting_template.py. -""" - -import argparse -import sys - -from apiclient.http import MediaFileUpload -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to configure dynamic asset selection for') -argparser.add_argument( - 'creative_id', type=int, - help='The ID of the in-stream video creative to configure selection for.') -argparser.add_argument( - 'template_id', type=int, - help='The ID of the template to use for targeting.') -argparser.add_argument( - 'video_name', help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_video_file', help='Path to the asset file to be uploaded.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - creative_id = flags.creative_id - template_id = flags.template_id - path_to_video_file = flags.path_to_video_file - video_name = flags.video_name - - try: - # Retrieve the specified creative. - creative = service.creatives().get(profileId=profile_id, - id=creative_id).execute() - - if not creative or creative['type'] != 'INSTREAM_VIDEO': - sys.exit('Invalid creative specified.') - - if 'creativeAssetSelection' not in creative: - # Locate an existing video asset to use as a default. - default_asset_id = next((asset['id'] - for asset in creative['creativeAssets'] - if asset['role'] == 'PARENT_VIDEO'), None) - - if not default_asset_id: - sys.exit('Default video asset could not be found.') - - # Enable dynamic asset selection for the creative. - creative['dynamicAssetSelection'] = True - - # Create a new selection using the existing asset as a default. - creative['creativeAssetSelection'] = { - 'defaultAssetId': default_asset_id, - 'rules': [] - } - - # Upload the new video asset and add it to the creative. - video_asset = upload_creative_asset( - service, profile_id, creative['advertiserId'], video_name, - path_to_video_file, 'VIDEO') - - creative['creativeAssets'].append({ - 'assetIdentifier': video_asset['assetIdentifier'], - 'role': 'PARENT_VIDEO' - }) - - # Create a rule targeting the new video asset and add it to the creative. - creative['creativeAssetSelection']['rules'].append({ - 'assetId': video_asset['id'], - 'name': 'Test rule for asset %s' % video_asset['id'], - 'targetingTemplateId': template_id - }) - - request = service.creatives().update(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Dynamic asset selection enabled for creative with ID %s.' - % response['id']) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def upload_creative_asset( - service, profile_id, advertiser_id, asset_name, path_to_asset_file, - asset_type): - """Uploads a creative asset and returns a creative asset metadata object.""" - # Construct the creative asset metadata - creative_asset = { - 'assetIdentifier': { - 'name': asset_name, - 'type': asset_type - } - } - - media = MediaFileUpload(path_to_asset_file) - if not media.mimetype(): - media = MediaFileUpload(path_to_asset_file, 'application/octet-stream') - - response = service.creativeAssets().insert( - advertiserId=advertiser_id, - profileId=profile_id, - media_body=media, - body=creative_asset).execute() - - return response - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_advertiser.py b/python/v4/create_advertiser.py deleted file mode 100755 index f396e99..0000000 --- a/python/v4/create_advertiser.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an advertiser in a given DFA account.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add an advertiser for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct and save advertiser. - advertiser = { - 'name': 'Test Advertiser', - 'status': 'APPROVED' - } - - request = service.advertisers().insert( - profileId=profile_id, body=advertiser) - - # Execute request and print response. - response = request.execute() - - print ('Created advertiser with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_advertiser_group.py b/python/v4/create_advertiser_group.py deleted file mode 100755 index 02a1edd..0000000 --- a/python/v4/create_advertiser_group.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an advertiser group.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add an advertiser group for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct and save advertiser. - advertiser_group = { - 'name': 'Test Advertiser Group' - } - - request = service.advertiserGroups().insert( - profileId=profile_id, body=advertiser_group) - - # Execute request and print response. - response = request.execute() - - print ('Created advertiser group with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_advertiser_landing_page.py b/python/v4/create_advertiser_landing_page.py deleted file mode 100755 index aab6db9..0000000 --- a/python/v4/create_advertiser_landing_page.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2017 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an advertiser landing page.""" - -import argparse -import sys -import uuid - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', - type=int, - help='The ID of the profile to add an advertiser landing page for') -argparser.add_argument( - 'advertiser_id', - type=int, - help='The ID of the advertiser to associate the landing page with') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct a landing page object. - landing_page = { - 'name': 'Test Landing Page #%s' % uuid.uuid4(), - 'advertiserId': advertiser_id, - 'archived': 'false', - 'url': 'https://www.google.com' - } - - request = service.advertiserLandingPages().insert( - profileId=profile_id, body=landing_page) - - # Execute request and print response. - response = request.execute() - - print('Created advertiser landing page with ID %s and name "%s".' % - (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_campaign.py b/python/v4/create_campaign.py deleted file mode 100755 index a946587..0000000 --- a/python/v4/create_campaign.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a campaign in a given advertiser. - -To create an advertiser, run create_advertiser.py. -""" - -import argparse -import sys -import uuid - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to add a campaign for') -argparser.add_argument( - 'advertiser_id', - type=int, - help='The ID of the advertiser to associate the campaign with') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Locate an advertiser landing page to use as a default. - default_landing_page = get_advertiser_landing_page(service, profile_id, - advertiser_id) - - # Construct and save campaign. - campaign = { - 'name': 'Test Campaign #%s' % uuid.uuid4(), - 'advertiserId': advertiser_id, - 'archived': 'false', - 'defaultLandingPageId': default_landing_page['id'], - 'startDate': '2015-01-01', - 'endDate': '2020-01-01' - } - - request = service.campaigns().insert(profileId=profile_id, body=campaign) - - # Execute request and print response. - response = request.execute() - - print('Created campaign with ID %s and name "%s".' % (response['id'], - response['name'])) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def get_advertiser_landing_page(service, profile_id, advertiser_id): - # Retrieve a single landing page from the specified advertiser. - response = service.advertiserLandingPages().list( - profileId=profile_id, advertiserIds=[advertiser_id], - maxResults=1).execute() - - if not response['landingPages']: - sys.exit( - 'No landing pages found for advertiser with ID %d.' % advertiser_id) - - return response['landingPages'][0] - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_campaign_event_tag.py b/python/v4/create_campaign_event_tag.py deleted file mode 100755 index 4d061de..0000000 --- a/python/v4/create_campaign_event_tag.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an event tag for the specified campaign.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add an event tag for') -argparser.add_argument( - 'campaign_id', type=int, - help='The ID of the campaign to add an event tag for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - campaign_id = flags.campaign_id - - try: - # Construct and save event tag. - event_tag = { - 'campaignId': campaign_id, - 'name': 'Test Campaign Event Tag', - 'status': 'ENABLED', - 'type': 'CLICK_THROUGH_EVENT_TAG', - 'url': 'https://www.google.com' - } - - request = service.eventTags().insert(profileId=profile_id, body=event_tag) - - # Execute request and print response. - response = request.execute() - - print ('Created campaign event tag with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_content_category.py b/python/v4/create_content_category.py deleted file mode 100755 index c13ccfd..0000000 --- a/python/v4/create_content_category.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a content category with given name and description.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a content category for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct and save content category. - content_category = { - 'name': 'Test Category' - } - - request = service.contentCategories().insert( - profileId=profile_id, body=content_category) - - # Execute request and print response. - response = request.execute() - - print ('Created content category with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_creative_field.py b/python/v4/create_creative_field.py deleted file mode 100644 index 1f3655e..0000000 --- a/python/v4/create_creative_field.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a creative field associated with a given advertiser. - -To get an advertiser ID, run get_advertisers.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a creative field for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to add a creative field for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct and save creative field - creative_field = { - 'advertiserId': advertiser_id, - 'name': 'Test Creative Field' - } - - request = service.creativeFields().insert( - profileId=profile_id, body=creative_field) - - # Execute request and print response. - response = request.execute() - - print ('Created creative field with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_creative_field_value.py b/python/v4/create_creative_field_value.py deleted file mode 100644 index 21413a4..0000000 --- a/python/v4/create_creative_field_value.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a creative field value for a given creative field. - -To get the creative field ID, run get_creative_fields.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a creative field value for') -argparser.add_argument( - 'field_id', type=int, - help='The ID of the creative field to add a value for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - field_id = flags.field_id - - try: - # Construct and save creative field value - field_value = { - 'value': 'Test Creative Field Value' - } - - request = service.creativeFieldValues().insert( - profileId=profile_id, creativeFieldId=field_id, body=field_value) - - # Execute request and print response. - response = request.execute() - - print ('Created creative field value with ID %s and value "%s".' - % (response['id'], response['value'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_creative_group.py b/python/v4/create_creative_group.py deleted file mode 100644 index c852e1e..0000000 --- a/python/v4/create_creative_group.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a creative group associated with a given advertiser. - -To get an advertiser ID, run get_advertisers.py. Valid group numbers are -limited to 1 or 2. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a creative group for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to add a creative group for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct and save creative group - creative_group = { - 'advertiserId': advertiser_id, - 'groupNumber': 1, - 'name': 'Test Creative Group' - } - - request = service.creativeGroups().insert( - profileId=profile_id, body=creative_group) - - # Execute request and print response. - response = request.execute() - - print ('Created creative group with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_display_image_gallery_creative.py b/python/v4/create_display_image_gallery_creative.py deleted file mode 100755 index 624a9ab..0000000 --- a/python/v4/create_display_image_gallery_creative.py +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a display image gallery creative. - -Requires two image assets and an advertiser ID as input. To get an advertiser -ID, run get_advertisers.py. -""" - -import argparse -import sys - -from apiclient.http import MediaFileUpload -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to associate this creative with.') -argparser.add_argument( - 'size_id', type=int, - help='The ID of the size of this creative.') -argparser.add_argument( - 'image1_name', - help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_image1_file', - help='Path to the asset file to be uploaded.') -argparser.add_argument( - 'image2_name', - help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_image2_file', - help='Path to the asset file to be uploaded.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - image1_name = flags.image1_name - image2_name = flags.image2_name - path_to_image1_file = flags.path_to_image1_file - path_to_image2_file = flags.path_to_image2_file - size_id = flags.size_id - - try: - # Upload the first image asset - image1_asset_id = upload_creative_asset( - service, profile_id, advertiser_id, image1_name, path_to_image1_file, - 'HTML_IMAGE') - - # Upload the second image asset - image2_asset_id = upload_creative_asset( - service, profile_id, advertiser_id, image2_name, path_to_image2_file, - 'HTML_IMAGE') - - # Construct the creative structure. - creative = { - 'advertiserId': advertiser_id, - 'autoAdvanceImages': True, - 'clickTags': [ - {'eventName': image1_asset_id['name'], - 'name': image1_asset_id['name']}, - {'eventName': image2_asset_id['name'], - 'name': image2_asset_id['name']} - ], - 'creativeAssets': [ - {'assetIdentifier': image1_asset_id, 'role': 'PRIMARY'}, - {'assetIdentifier': image2_asset_id, 'role': 'PRIMARY'}, - ], - 'name': 'Test display image gallery creative', - 'size': {'id': size_id}, - 'type': 'DISPLAY_IMAGE_GALLERY' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Created display image gallery creative with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def upload_creative_asset( - service, profile_id, advertiser_id, asset_name, path_to_asset_file, - asset_type): - """Uploads a creative asset and returns an assetIdentifier.""" - # Construct the creative asset metadata - creative_asset = { - 'assetIdentifier': { - 'name': asset_name, - 'type': asset_type - } - } - - media = MediaFileUpload(path_to_asset_file) - if not media.mimetype(): - media = MediaFileUpload(path_to_asset_file, 'application/octet-stream') - - response = service.creativeAssets().insert( - advertiserId=advertiser_id, - profileId=profile_id, - media_body=media, - body=creative_asset).execute() - - return response['assetIdentifier'] - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_display_redirect_creative.py b/python/v4/create_display_redirect_creative.py deleted file mode 100755 index 3f2c7b8..0000000 --- a/python/v4/create_display_redirect_creative.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a display redirect creative. - -To get a size ID, run get_size.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to associate this creative with.') -argparser.add_argument( - 'image_url', - help='URL of the image to associate with this creative.') -argparser.add_argument( - 'size_id', type=int, - help='The ID of the size of the specified image.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - image_url = flags.image_url - size_id = flags.size_id - - try: - # Construct the basic creative structure. - creative = { - 'advertiserId': advertiser_id, - 'name': 'Test display redirect creative', - 'redirect_url': image_url, - 'size': {'id': size_id}, - 'type': 'DISPLAY_REDIRECT' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Created display redirect creative with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_floodlight_activity.py b/python/v4/create_floodlight_activity.py deleted file mode 100755 index db11f5e..0000000 --- a/python/v4/create_floodlight_activity.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a floodlight activity in a given activity group. - -To create an activity group, run create_floodlight_activity_group.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement for') -argparser.add_argument( - 'activity_group_id', type=int, - help='The ID of the floodlight activity group to create an activity for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - activity_group_id = flags.activity_group_id - - try: - # Construct and save floodlight activity. - floodlight_activity = { - 'countingMethod': 'STANDARD_COUNTING', - 'expectedUrl': 'http://www.google.com', - 'floodlightActivityGroupId': activity_group_id, - 'floodlightTagType': 'GLOBAL_SITE_TAG', - 'name': 'Test Floodlight Activity' - } - - request = service.floodlightActivities().insert( - profileId=profile_id, body=floodlight_activity) - - # Execute request and print response. - response = request.execute() - - print ('Created floodlight activity with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_floodlight_activity_group.py b/python/v4/create_floodlight_activity_group.py deleted file mode 100755 index 7075be8..0000000 --- a/python/v4/create_floodlight_activity_group.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a new activity group for a floodlight configuration. - -To get a floodlight configuration ID, run get_advertisers.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement for') -argparser.add_argument( - 'floodlight_config_id', type=int, - help='The ID of the floodlight config to create a group for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - floodlight_config_id = flags.floodlight_config_id - - try: - # Construct and save floodlight activity group. - activity_group = { - 'name': 'Test Floodlight Activity Group', - 'floodlightConfigurationId': floodlight_config_id, - 'type': 'COUNTER' - } - - request = service.floodlightActivityGroups().insert( - profileId=profile_id, body=activity_group) - - # Execute request and print response. - response = request.execute() - - print ('Created floodlight activity group with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_html5_display_creative.py b/python/v4/create_html5_display_creative.py deleted file mode 100755 index f3ab214..0000000 --- a/python/v4/create_html5_display_creative.py +++ /dev/null @@ -1,150 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an HTML5 display creative. - -Requires an HTML5 asset, backup image asset, and an advertiser ID as input. -To get an advertiser ID, run get_advertisers.py. -""" - -import argparse -import sys - -from apiclient.http import MediaFileUpload -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', - type=int, - help='The ID of the advertiser to associate this creative with.') -argparser.add_argument( - 'size_id', type=int, help='The ID of the size of this creative.') -argparser.add_argument( - 'html5_asset_name', - help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_html5_asset_file', help='Path to the asset file to be uploaded.') -argparser.add_argument( - 'backup_image_name', - help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_backup_image_file', help='Path to the asset file to be uploaded.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - backup_image_name = flags.backup_image_name - html5_asset_name = flags.html5_asset_name - path_to_backup_image_file = flags.path_to_backup_image_file - path_to_html5_asset_file = flags.path_to_html5_asset_file - size_id = flags.size_id - - try: - # Locate an advertiser landing page to use as a default. - default_landing_page = get_advertiser_landing_page(service, profile_id, - advertiser_id) - - # Upload the HTML5 asset - html5_asset_id = upload_creative_asset(service, profile_id, advertiser_id, - html5_asset_name, - path_to_html5_asset_file, 'HTML') - - # Upload the backup image asset - backup_image_asset_id = upload_creative_asset( - service, profile_id, advertiser_id, backup_image_name, - path_to_backup_image_file, 'HTML_IMAGE') - - # Construct the creative structure. - creative = { - 'advertiserId': advertiser_id, - 'backupImageClickThroughUrl': { - 'landingPageId': default_landing_page['id'] - }, - 'backupImageReportingLabel': 'backup_image_exit', - 'backupImageTargetWindow': {'targetWindowOption': 'NEW_WINDOW'}, - 'clickTags': [{ - 'eventName': 'exit', - 'name': 'click_tag', - 'clickThroughUrl': {'landingPageId': default_landing_page['id']} - }], - 'creativeAssets': [ - {'assetIdentifier': html5_asset_id, 'role': 'PRIMARY'}, - {'assetIdentifier': backup_image_asset_id, 'role': 'BACKUP_IMAGE'} - ], - 'name': 'Test HTML5 display creative', - 'size': {'id': size_id}, - 'type': 'DISPLAY' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print('Created HTML5 display creative with ID %s and name "%s".' % - (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def get_advertiser_landing_page(service, profile_id, advertiser_id): - # Retrieve a single landing page from the specified advertiser. - response = service.advertiserLandingPages().list( - profileId=profile_id, advertiserIds=[advertiser_id], - maxResults=1).execute() - - if not response['landingPages']: - sys.exit( - 'No landing pages found for advertiser with ID %d.' % advertiser_id) - - return response['landingPages'][0] - - -def upload_creative_asset(service, profile_id, advertiser_id, asset_name, - path_to_asset_file, asset_type): - """Uploads a creative asset and returns an assetIdentifier.""" - # Construct the creative asset metadata - creative_asset = {'assetIdentifier': {'name': asset_name, 'type': asset_type}} - - media = MediaFileUpload(path_to_asset_file) - if not media.mimetype(): - media = MediaFileUpload(path_to_asset_file, 'application/octet-stream') - - response = service.creativeAssets().insert( - advertiserId=advertiser_id, - profileId=profile_id, - media_body=media, - body=creative_asset).execute() - - return response['assetIdentifier'] - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_image_display_creative.py b/python/v4/create_image_display_creative.py deleted file mode 100755 index dd5ec44..0000000 --- a/python/v4/create_image_display_creative.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an image display creative. - -Requires an image asset and advertiser ID as input. To get an advertiser ID, -run get_advertisers.py. -""" - -import argparse -import sys - -from apiclient.http import MediaFileUpload -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to associate this creative with.') -argparser.add_argument( - 'size_id', type=int, - help='The ID of the size of this creative.') -argparser.add_argument( - 'image_name', - help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_image_file', - help='Path to the asset file to be uploaded.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - image_name = flags.image_name - path_to_image_file = flags.path_to_image_file - size_id = flags.size_id - - try: - # Upload the creative asset - creative_asset_id = upload_creative_asset( - service, profile_id, advertiser_id, image_name, path_to_image_file, - 'HTML_IMAGE') - - # Construct the creative structure. - creative = { - 'advertiserId': advertiser_id, - 'creativeAssets': [ - {'assetIdentifier': creative_asset_id, 'role': 'PRIMARY'} - ], - 'name': 'Test image display creative', - 'size': {'id': size_id}, - 'type': 'DISPLAY' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Created image display creative with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def upload_creative_asset( - service, profile_id, advertiser_id, asset_name, path_to_asset_file, - asset_type): - """Uploads a creative asset and returns an assetIdentifier.""" - # Construct the creative asset metadata - creative_asset = { - 'assetIdentifier': { - 'name': asset_name, - 'type': asset_type - } - } - - media = MediaFileUpload(path_to_asset_file) - if not media.mimetype(): - media = MediaFileUpload(path_to_asset_file, 'application/octet-stream') - - response = service.creativeAssets().insert( - advertiserId=advertiser_id, - profileId=profile_id, - media_body=media, - body=creative_asset).execute() - - return response['assetIdentifier'] - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_instream_audio_creative.py b/python/v4/create_instream_audio_creative.py deleted file mode 100755 index 5c996c1..0000000 --- a/python/v4/create_instream_audio_creative.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an in-stream audio creative. - -Requires an audio asset and advertiser ID as input. To get an advertiser ID, -run get_advertisers.py. -""" - -import argparse -import sys - -from apiclient.http import MediaFileUpload -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to associate this creative with.') -argparser.add_argument( - 'audio_name', help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_audio_file', help='Path to the asset file to be uploaded.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - path_to_audio_file = flags.path_to_audio_file - audio_name = flags.audio_name - - try: - # Upload the creative asset - creative_asset_id = upload_creative_asset( - service, profile_id, advertiser_id, audio_name, path_to_audio_file, - 'AUDIO') - - # Construct the creative structure. - creative = { - 'advertiserId': advertiser_id, - 'creativeAssets': [ - {'assetIdentifier': creative_asset_id, 'role': 'PARENT_AUDIO'} - ], - 'name': 'Test in-stream audio creative', - 'type': 'INSTREAM_AUDIO' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Created in-stream audio creative with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def upload_creative_asset( - service, profile_id, advertiser_id, asset_name, path_to_asset_file, - asset_type): - """Uploads a creative asset and returns an assetIdentifier.""" - # Construct the creative asset metadata - creative_asset = { - 'assetIdentifier': { - 'name': asset_name, - 'type': asset_type - } - } - - media = MediaFileUpload(path_to_asset_file) - if not media.mimetype(): - media = MediaFileUpload(path_to_asset_file, 'application/octet-stream') - - response = service.creativeAssets().insert( - advertiserId=advertiser_id, - profileId=profile_id, - media_body=media, - body=creative_asset).execute() - - return response['assetIdentifier'] - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_instream_video_creative.py b/python/v4/create_instream_video_creative.py deleted file mode 100755 index 4cc64af..0000000 --- a/python/v4/create_instream_video_creative.py +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an in-stream video creative. - -Requires a video asset and advertiser ID as input. To get an advertiser ID, -run get_advertisers.py. -""" - -import argparse -import sys - -from apiclient.http import MediaFileUpload -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to associate this creative with.') -argparser.add_argument( - 'video_name', help='Suggested name to use for the uploaded creative asset.') -argparser.add_argument( - 'path_to_video_file', help='Path to the asset file to be uploaded.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - path_to_video_file = flags.path_to_video_file - video_name = flags.video_name - - try: - # Upload the creative asset - creative_asset_id = upload_creative_asset( - service, profile_id, advertiser_id, video_name, path_to_video_file, - 'VIDEO') - - # Construct the creative structure. - creative = { - 'advertiserId': advertiser_id, - 'creativeAssets': [ - {'assetIdentifier': creative_asset_id, 'role': 'PARENT_VIDEO'} - ], - 'name': 'Test in-stream video creative', - 'type': 'INSTREAM_VIDEO' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Created in-stream video creative with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def upload_creative_asset( - service, profile_id, advertiser_id, asset_name, path_to_asset_file, - asset_type): - """Uploads a creative asset and returns an assetIdentifier.""" - # Construct the creative asset metadata - creative_asset = { - 'assetIdentifier': { - 'name': asset_name, - 'type': asset_type - } - } - - media = MediaFileUpload(path_to_asset_file) - if not media.mimetype(): - media = MediaFileUpload(path_to_asset_file, 'application/octet-stream') - - response = service.creativeAssets().insert( - advertiserId=advertiser_id, - profileId=profile_id, - media_body=media, - body=creative_asset).execute() - - return response['assetIdentifier'] - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_placement.py b/python/v4/create_placement.py deleted file mode 100755 index 762ed6e..0000000 --- a/python/v4/create_placement.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates an agency paid regular placement in a given campaign. - -Requires the DFA site ID and campaign ID in which the placement will be created -into. To create a campaign, run create_campaign.py. To get DFA site ID, run -get_site.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement for') -argparser.add_argument( - 'campaign_id', type=int, - help='The ID of the campaign to associate the placement with') -argparser.add_argument( - 'site_id', type=int, - help='The ID of the site to associate the placement with') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - campaign_id = flags.campaign_id - site_id = flags.site_id - - try: - # Look up the campaign - campaign = service.campaigns().get( - profileId=profile_id, id=campaign_id).execute() - - # Construct and save placement. - placement = { - 'name': 'Test Placement', - 'campaignId': campaign_id, - 'compatibility': 'DISPLAY', - 'siteId': site_id, - 'size': { - 'height': '1', - 'width': '1' - }, - 'paymentSource': 'PLACEMENT_AGENCY_PAID', - 'tagFormats': ['PLACEMENT_TAG_STANDARD'] - } - - # Set the pricing schedule for the placement. - placement['pricingSchedule'] = { - 'startDate': campaign['startDate'], - 'endDate': campaign['endDate'], - 'pricingType': 'PRICING_TYPE_CPM' - } - - request = service.placements().insert(profileId=profile_id, body=placement) - - # Execute request and print response. - response = request.execute() - - print ('Created placement with ID %s and name "%s".' - % (long(response['id']), response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_placement_group.py b/python/v4/create_placement_group.py deleted file mode 100755 index 4103571..0000000 --- a/python/v4/create_placement_group.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a placement group in a given campaign. - -Requires the DFA site ID and campaign ID in which the placement group will be -created into. To create a campaign, run create_campaign.py. To get DFA site ID, -run get_site.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement group for') -argparser.add_argument( - 'campaign_id', type=int, - help='The ID of the campaign to associate the placement group with') -argparser.add_argument( - 'site_id', type=int, - help='The ID of the site to associate the placement group with') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - campaign_id = flags.campaign_id - site_id = flags.site_id - - try: - # Look up the campaign - campaign = service.campaigns().get( - profileId=profile_id, id=campaign_id).execute() - - # Construct and save placement. - placement_group = { - 'name': 'Test Placement Group', - 'campaignId': campaign_id, - 'siteId': site_id, - 'placementGroupType': 'PLACEMENT_PACKAGE', - 'pricingSchedule': { - 'startDate': campaign['startDate'], - 'endDate': campaign['endDate'], - 'pricingType': 'PRICING_TYPE_CPM' - } - } - - request = service.placementGroups().insert( - profileId=profile_id, body=placement_group) - - # Execute request and print response. - response = request.execute() - - print ('Created placement group with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_placement_strategy.py b/python/v4/create_placement_strategy.py deleted file mode 100755 index d5c8bf5..0000000 --- a/python/v4/create_placement_strategy.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a placement strategy with the given name.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement strategy for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct and save placement strategy. - placement_strategy = { - 'name': 'Test Strategy' - } - - request = service.placementStrategies().insert( - profileId=profile_id, body=placement_strategy) - - # Execute request and print response. - response = request.execute() - - print ('Created placement strategy with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_remarketing_list.py b/python/v4/create_remarketing_list.py deleted file mode 100644 index 644b401..0000000 --- a/python/v4/create_remarketing_list.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Creates a remarketing list for a given advertiser and floodlight activity. - -Note: this sample assumes that the floodlight activity specified has a U1 custom -floodlight variable. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a remarketing list for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to add a remarketing list for') -argparser.add_argument( - 'activity_id', type=int, - help='The ID of the floodlight activity to add a remarketing list for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - activity_id = flags.activity_id - - try: - # Create a list population term. - # This term matches all visitors with a U1 value exactly matching - # "test_value" - term = { - 'operator': 'STRING_EQUALS', - 'type': 'CUSTOM_VARIABLE_TERM', - 'value': 'test_value', - 'variableName': 'U1' - } - - # Add the term to a clause and the clause to a population rule. - # This rule will target all visitors who trigger the specified floodlight - # activity and satisfy the custom rule defined in the list population term. - rule = { - 'floodlightActivityId': activity_id, - 'listPopulationClauses': {'terms': [term]} - } - - # Create the remarketing list. - remarketing_list = { - 'name': 'Test Remarketing List', - 'active': 'true', - 'advertiserId': advertiser_id, - 'lifeSpan': 30, - 'listPopulationRule': rule - } - - request = service.remarketingLists().insert( - profileId=profile_id, body=remarketing_list) - - # Execute request and print response. - response = request.execute() - - print ('Created remarketing list with ID %s and name "%s."' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_report.py b/python/v4/create_report.py deleted file mode 100644 index e51aaa1..0000000 --- a/python/v4/create_report.py +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""An end-to-end example of how to create and configure a standard report.""" - -import argparse -from datetime import date -from datetime import timedelta -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to create a report for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # 1. Create a report resource. - report = create_report_resource() - - # 2. Define the report criteria. - define_report_criteria(report) - - # 3. (optional) Look up compatible fields. - find_compatible_fields(service, profile_id, report) - - # 4. Add dimension filters to the report criteria. - add_dimension_filters(service, profile_id, report) - - # 5. Save the report resource. - report = insert_report_resource(service, profile_id, report) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def create_report_resource(): - """Creates a report resource.""" - report = { - # Set the required fields "name" and "type". - 'name': 'Example Standard Report', - 'type': 'STANDARD', - # Set optional fields. - 'fileName': 'example_report', - 'format': 'CSV' - } - - print 'Creating %s report resource with name "%s".' % (report['type'], - report['name']) - - return report - - -def define_report_criteria(report): - """Defines a criteria for the report.""" - # Define a date range to report on. This example uses explicit start and end - # dates to mimic the "LAST_30_DAYS" relative date range. - end_date = date.today() - start_date = end_date - timedelta(days=30) - - # Create a report criteria. - criteria = { - 'dateRange': { - 'startDate': start_date.strftime('%Y-%m-%d'), - 'endDate': end_date.strftime('%Y-%m-%d') - }, - 'dimensions': [{ - 'name': 'advertiser' - }], - 'metricNames': ['clicks', 'impressions'] - } - - # Add the criteria to the report resource. - report['criteria'] = criteria - - print '\nAdded report criteria:\n%s' % criteria - - -def find_compatible_fields(service, profile_id, report): - """Finds and adds a compatible dimension/metric to the report.""" - fields = service.reports().compatibleFields().query( - profileId=profile_id, body=report).execute() - - report_fields = fields['reportCompatibleFields'] - - if report_fields['dimensions']: - # Add a compatible dimension to the report. - report['criteria']['dimensions'].append({ - 'name': report_fields['dimensions'][0]['name'] - }) - elif report_fields['metrics']: - # Add a compatible metric to the report. - report['criteria']['metricNames'].append( - report_fields['metrics'][0]['name']) - - print('\nUpdated report criteria (with compatible fields):\n%s' % - report['criteria']) - - -def add_dimension_filters(service, profile_id, report): - """Finds and adds a valid dimension filter to the report.""" - # Query advertiser dimension values for report run dates. - request = { - 'dimensionName': 'advertiser', - 'endDate': report['criteria']['dateRange']['endDate'], - 'startDate': report['criteria']['dateRange']['startDate'] - } - - values = service.dimensionValues().query( - profileId=profile_id, body=request).execute() - - if values['items']: - # Add a value as a filter to the report criteria. - report['criteria']['dimensionFilters'] = [values['items'][0]] - - print('\nUpdated report criteria (with valid dimension filters):\n%s' % - report['criteria']) - - -def insert_report_resource(service, profile_id, report): - """Inserts the report.""" - inserted_report = service.reports().insert( - profileId=profile_id, body=report).execute() - - print('\nSuccessfully inserted new report with ID %s.' % - inserted_report['id']) - - return inserted_report - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_rotation_group.py b/python/v4/create_rotation_group.py deleted file mode 100644 index 8286711..0000000 --- a/python/v4/create_rotation_group.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a rotation group ad in a given campaign.""" - -import argparse -import sys -import time - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a rotation group for') -argparser.add_argument( - 'campaign_id', type=int, - help='The ID of the campaign to add a rotation group for') -argparser.add_argument( - 'placement_id', type=int, - help='The ID of the placement to add a rotation group for') -argparser.add_argument( - 'creative_id', type=int, - help='The ID of the creative to add to the rotation group') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - campaign_id = flags.campaign_id - placement_id = flags.placement_id - creative_id = flags.creative_id - - try: - # Retrieve the campaign (to get end date). - campaign = service.campaigns().get( - profileId=profile_id, id=campaign_id).execute() - - # Construct creative assignment. - creative_assignment = { - 'active': 'true', - 'creativeId': creative_id, - 'clickThroughUrl': { - 'defaultLandingPage': 'true' - } - } - - # Construct placement assignment. - placement_assignment = { - 'active': 'true', - 'placementId': placement_id, - } - - # Construct creative rotation. - creative_rotation = { - 'creativeAssignments': [creative_assignment], - 'type': 'CREATIVE_ROTATION_TYPE_RANDOM', - 'weightCalculationStrategy': 'WEIGHT_STRATEGY_OPTIMIZED' - } - - # Construct delivery schedule. - delivery_schedule = { - 'impressionRatio': '1', - 'priority': 'AD_PRIORITY_01' - } - - # Construct and save ad. - ad = { - 'active': 'true', - 'campaignId': campaign_id, - 'creativeRotation': creative_rotation, - 'deliverySchedule': delivery_schedule, - 'endTime': '%sT00:00:00Z' % campaign['endDate'], - 'name': 'Test Rotation Group', - 'placementAssignments': [placement_assignment], - 'startTime': '%sT23:59:59Z' % time.strftime('%Y-%m-%d'), - 'type': 'AD_SERVING_STANDARD_AD' - } - - request = service.ads().insert(profileId=profile_id, body=ad) - - # Execute request and print response. - response = request.execute() - - print ('Created rotation group with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_subaccount.py b/python/v4/create_subaccount.py deleted file mode 100755 index c463c68..0000000 --- a/python/v4/create_subaccount.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a subaccount in a given DFA account. - -To get the account ID, run get_all_userprofiles.py. To get the available -permissions, run get_user_role_permissions.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a subaccount for') -argparser.add_argument( - 'account_id', type=int, - help='The ID of the account to create a subaccount for') -argparser.add_argument( - 'permission_id', type=int, - help='The ID of the permission to apply to this subaccount') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - account_id = flags.account_id - permission_id = flags.permission_id - - try: - # Construct the basic subaccount structure. - subaccount = { - 'name': 'Test Subaccount', - 'accountId': account_id, - 'availablePermissionIds': [permission_id] - } - - request = service.subaccounts().insert( - profileId=profile_id, body=subaccount) - - # Execute request and print response. - response = request.execute() - - print ('Created subaccount with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_targeting_template.py b/python/v4/create_targeting_template.py deleted file mode 100644 index 16901c1..0000000 --- a/python/v4/create_targeting_template.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a targeting template associated with a given advertiser. - -To get an advertiser ID, run get_advertisers.py. -""" - -import argparse -import sys -import uuid - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a targeting template for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to add a targeting template for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct a basic targeting template. - # This template will be configured to serve ads on Monday, Wednesday, and - # Friday from 9-10am and 3-5pm. - # Note: targeting template names must be unique within an advetiser. - targeting_template = { - 'advertiserId': advertiser_id, - 'dayPartTargeting': { - 'daysOfWeek': ['MONDAY', 'WEDNESDAY', 'FRIDAY'], - 'hoursOfDay': [9, 15, 16], - 'userLocalTime': True - }, - 'name': 'Test Targeting Template #%s' % uuid.uuid4() - } - - request = service.targetingTemplates().insert(profileId=profile_id, - body=targeting_template) - - # Execute request and print response. - response = request.execute() - - print ('Created targeting template with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_tracking_creative.py b/python/v4/create_tracking_creative.py deleted file mode 100755 index 6bbc0a3..0000000 --- a/python/v4/create_tracking_creative.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a tracking creative associated with an advertiser.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a user role for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to associate this creative with.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the basic creative structure. - creative = { - 'advertiserId': advertiser_id, - 'name': 'Test tracking creative', - 'type': 'TRACKING_TEXT' - } - - request = service.creatives().insert(profileId=profile_id, body=creative) - - # Execute request and print response. - response = request.execute() - - print ('Created tracking creative with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/create_user_role.py b/python/v4/create_user_role.py deleted file mode 100755 index 829cd34..0000000 --- a/python/v4/create_user_role.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example creates a user role in a given DFA account. - -To get the account ID, run get_all_userprofiles.py. To get the parent user role -ID, run get_user_roles.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a user role for') -argparser.add_argument( - 'account_id', type=int, - help='The ID of the subaccount to create a user role for') -argparser.add_argument( - 'parent_role_id', type=int, - help='The ID of the parent user role to assign to this user role') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - account_id = flags.account_id - parent_role_id = flags.parent_role_id - - try: - # Construct the basic user role structure. - user_role = { - 'name': 'Test User Role', - 'accountId': account_id, - 'parentUserRoleId': parent_role_id - } - - request = service.userRoles().insert(profileId=profile_id, body=user_role) - - # Execute request and print response. - response = request.execute() - - print ('Created user role with ID %s and name "%s".' - % (response['id'], response['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/delete_report.py b/python/v4/delete_report.py deleted file mode 100644 index 4f615b8..0000000 --- a/python/v4/delete_report.py +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to delete a report.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to delete a report for') -argparser.add_argument( - 'report_id', type=int, - help='The ID of the report to delete') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - report_id = flags.report_id - - try: - # Construct the request. - request = service.reports().delete(profileId=profile_id, reportId=report_id) - - # Execute request and print response. - request.execute() - - print 'Successfully deleted report with ID %s.' % report_id - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/dfareporting_utils.py b/python/v4/dfareporting_utils.py deleted file mode 100644 index fe36a64..0000000 --- a/python/v4/dfareporting_utils.py +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Handles common tasks across all API samples.""" - -import argparse -import os - -from googleapiclient import discovery -import httplib2 -from oauth2client import client -from oauth2client import file as oauthFile -from oauth2client import tools - - -API_NAME = 'dfareporting' -API_VERSION = 'v4' -API_SCOPES = ['https://www.googleapis.com/auth/dfareporting', - 'https://www.googleapis.com/auth/dfatrafficking', - 'https://www.googleapis.com/auth/ddmconversions'] - -# Filename used for the credential store. -CREDENTIAL_STORE_FILE = API_NAME + '.dat' - - -def get_arguments(argv, desc, parents=None): - """Validates and parses command line arguments. - - Args: - argv: list of strings, the command-line parameters of the application. - desc: string, a description of the sample being executed. - parents: list of argparse.ArgumentParser, additional command-line parsers. - - Returns: - The parsed command-line arguments. - """ - # Include the default oauth2client argparser - parent_parsers = [tools.argparser] - - if parents: - parent_parsers.extend(parents) - - parser = argparse.ArgumentParser( - description=desc, - formatter_class=argparse.RawDescriptionHelpFormatter, - parents=parent_parsers) - return parser.parse_args(argv[1:]) - - -def load_application_default_credentials(): - """Atempts to load application default credentials. - - Returns: - A credential object initialized with application default credentials or None - if none were found. - """ - try: - credentials = client.GoogleCredentials.get_application_default() - return credentials.create_scoped(API_SCOPES) - except client.ApplicationDefaultCredentialsError: - # No application default credentials, continue to try other options. - pass - - -def load_user_credentials(client_secrets, storage, flags): - """Attempts to load user credentials from the provided client secrets file. - - Args: - client_secrets: path to the file containing client secrets. - storage: the data store to use for caching credential information. - flags: command-line flags. - - Returns: - A credential object initialized with user account credentials. - """ - # Set up a Flow object to be used if we need to authenticate. - flow = client.flow_from_clientsecrets( - client_secrets, - scope=API_SCOPES, - message=tools.message_if_missing(client_secrets)) - - # Retrieve credentials from storage. - # If the credentials don't exist or are invalid run through the installed - # client flow. The storage object will ensure that if successful the good - # credentials will get written back to file. - credentials = storage.get() - if credentials is None or credentials.invalid: - credentials = tools.run_flow(flow, storage, flags) - - return credentials - - -def setup(flags): - """Handles authentication and loading of the API. - - Args: - flags: command-line flags obtained by calling ''get_arguments()''. - - Returns: - An initialized service object. - """ - # Load application default credentials if they're available. - credentials = load_application_default_credentials() - - # Otherwise, load credentials from the provided client secrets file. - if credentials is None: - # Name of a file containing the OAuth 2.0 information for this - # application, including client_id and client_secret, which are found - # on the Credentials tab on the Google Developers Console. - client_secrets = os.path.join(os.path.dirname(__file__), - 'client_secrets.json') - storage = oauthFile.Storage(CREDENTIAL_STORE_FILE) - credentials = load_user_credentials(client_secrets, storage, flags) - - # Authorize HTTP object with the prepared credentials. - http = credentials.authorize(http=httplib2.Http()) - - # Construct and return a service object via the discovery service. - return discovery.build(API_NAME, API_VERSION, http=http) diff --git a/python/v4/download_file.py b/python/v4/download_file.py deleted file mode 100644 index d529f51..0000000 --- a/python/v4/download_file.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to download a report file.""" - -import argparse -import io -import os -import sys - -import dfareporting_utils -from googleapiclient import http -from oauth2client import client - - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'report_id', type=int, - help='The ID of the report to get a file for') -argparser.add_argument( - 'file_id', type=int, - help='The ID of the file to get') - -# Chunk size to use when downloading report files. Defaults to 32MB. -CHUNK_SIZE = 32 * 1024 * 1024 - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - report_id = flags.report_id - file_id = flags.file_id - - try: - # Retrieve the file metadata. - report_file = service.files().get(reportId=report_id, - fileId=file_id).execute() - - if report_file['status'] == 'REPORT_AVAILABLE': - # Prepare a local file to download the report contents to. - out_file = io.FileIO(generate_file_name(report_file), mode='wb') - - # Create a get request. - request = service.files().get_media(reportId=report_id, fileId=file_id) - - # Create a media downloader instance. - # Optional: adjust the chunk size used when downloading the file. - downloader = http.MediaIoBaseDownload(out_file, request, - chunksize=CHUNK_SIZE) - - # Execute the get request and download the file. - download_finished = False - while download_finished is False: - _, download_finished = downloader.next_chunk() - - print('File %s downloaded to %s' - % (report_file['id'], os.path.realpath(out_file.name))) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def generate_file_name(report_file): - """Generates a report file name based on the file metadata.""" - # If no filename is specified, use the file ID instead. - file_name = report_file['fileName'] or report_file['id'] - extension = '.csv' if report_file['format'] == 'CSV' else '.xml' - return file_name + extension - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/download_floodlight_tag.py b/python/v4/download_floodlight_tag.py deleted file mode 100644 index 835289e..0000000 --- a/python/v4/download_floodlight_tag.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example downloads activity tags for a given floodlight activity.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to download tags for') -argparser.add_argument( - 'activity_id', - type=int, - help='The ID of the floodlight activity to download tags for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - activity_id = flags.activity_id - - try: - # Construct the request. - request = service.floodlightActivities().generatetag( - profileId=profile_id, floodlightActivityId=activity_id) - - # Execute request and print response. - response = request.execute() - - if 'globalSiteTagGlobalSnippet' in response: - # Print both global snippet and event snippet. - print('Global site tag global snippet:\n\n%s' % - response['globalSiteTagGlobalSnippet']) - print('\n\nGlobal site tag event snippet:\n\n%s' % - response['floodlightActivityTag']) - else: - # Print the Floodlight activity tag. - print('Floodlight activity tag:\n\n%s' % - response['floodlightActivityTag']) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/download_placement_tags.py b/python/v4/download_placement_tags.py deleted file mode 100644 index 57ca8cb..0000000 --- a/python/v4/download_placement_tags.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example downloads HTML Tags for a given campaign and placement ID. - -To create campaigns, run create_campaign.py. To create placements, run -create_placement.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to download tags for') -argparser.add_argument( - 'campaign_id', type=int, - help='The ID of the campaign to download tags for') -argparser.add_argument( - 'placement_id', type=int, - help='The ID of the placement to download tags for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - campaign_id = flags.campaign_id - placement_id = flags.placement_id - - try: - # Construct the request. - request = service.placements().generatetags( - profileId=profile_id, campaignId=campaign_id, - placementIds=[placement_id]) - - # Execute request and print response. - response = request.execute() - - for placement_tag in response['placementTags']: - print_placement_tag(placement_tag) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def print_placement_tag(placement_tag): - for tag_data in placement_tag['tagDatas']: - print ('%s - %s\n' - % (placement_tag['placementId'], tag_data['format'])) - - if 'impressionTag' in tag_data: - print '%s\n\n' % (tag_data['impressionTag']) - if 'clickTag' in tag_data: - print '%s\n\n' % (tag_data['clickTag']) - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/find_and_download_file.py b/python/v4/find_and_download_file.py deleted file mode 100644 index 552e4d5..0000000 --- a/python/v4/find_and_download_file.py +++ /dev/null @@ -1,149 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""An end-to-end example of how to find and download a report file.""" - -import argparse -import io -import os -import sys - -import dfareporting_utils -from googleapiclient import http -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to use') -argparser.add_argument( - 'report_id', type=int, help='The ID of the report to get a file for') - -# Chunk size to use when downloading report files. Defaults to 32MB. -CHUNK_SIZE = 32 * 1024 * 1024 - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - report_id = flags.report_id - - try: - # 1. Find a file to download. - report_file = find_file(service, profile_id, report_id) - - if report_file: - # 2. (optional) Generate browser URL. - generate_browser_url(service, report_id, report_file['id']) - - # 3. Directly download the file. - direct_download_file(service, report_id, report_file['id']) - else: - print 'No file found for profile ID %d and report ID %d.' % (profile_id, - report_id) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def find_file(service, profile_id, report_id): - """Finds a report file to download.""" - target = None - - request = service.reports().files().list( - profileId=profile_id, reportId=report_id) - - while True: - response = request.execute() - - for report_file in response['items']: - if is_target_file(report_file): - target = report_file - break - - if not target and response['items'] and response['nextPageToken']: - request = service.reports().files().list_next(request, response) - else: - break - - if target: - print 'Found file %s with filename "%s".' % (target['id'], - target['fileName']) - return target - - print 'Unable to find file for profile ID %d and report ID %d.' % (profile_id, - report_id) - return None - - -def is_target_file(report_file): - # Provide custom validation logic here. - # For example purposes, any available file is considered valid. - return report_file['status'] == 'REPORT_AVAILABLE' - - -def generate_browser_url(service, report_id, file_id): - """Prints the browser download URL for the file.""" - report_file = service.files().get( - reportId=report_id, fileId=file_id).execute() - browser_url = report_file['urls']['browserUrl'] - - print 'File %s has browser URL: %s.' % (report_file['id'], browser_url) - - -def direct_download_file(service, report_id, file_id): - """Downloads a report file to disk.""" - # Retrieve the file metadata. - report_file = service.files().get( - reportId=report_id, fileId=file_id).execute() - - if report_file['status'] == 'REPORT_AVAILABLE': - # Prepare a local file to download the report contents to. - out_file = io.FileIO(generate_file_name(report_file), mode='wb') - - # Create a get request. - request = service.files().get_media(reportId=report_id, fileId=file_id) - - # Create a media downloader instance. - # Optional: adjust the chunk size used when downloading the file. - downloader = http.MediaIoBaseDownload( - out_file, request, chunksize=CHUNK_SIZE) - - # Execute the get request and download the file. - download_finished = False - while download_finished is False: - _, download_finished = downloader.next_chunk() - - print('File %s downloaded to %s' % (report_file['id'], - os.path.realpath(out_file.name))) - - -def generate_file_name(report_file): - """Generates a report file name based on the file metadata.""" - # If no filename is specified, use the file ID instead. - file_name = report_file['fileName'] or report_file['id'] - extension = '.csv' if report_file['format'] == 'CSV' else '.xml' - return file_name + extension - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/find_and_run_report.py b/python/v4/find_and_run_report.py deleted file mode 100644 index 208bfd6..0000000 --- a/python/v4/find_and_run_report.py +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2018 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""An end-to-end example of how to find and run a report.""" - -import argparse -import random -import sys -import time - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to use') - -# The following values control retry behavior while the report is processing. -# Minimum amount of time between polling requests. Defaults to 10 seconds. -MIN_RETRY_INTERVAL = 10 -# Maximum amount of time between polling requests. Defaults to 10 minutes. -MAX_RETRY_INTERVAL = 10 * 60 -# Maximum amount of time to spend polling. Defaults to 1 hour. -MAX_RETRY_ELAPSED_TIME = 60 * 60 - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # 1. Find a report to run. - report = find_report(service, profile_id) - - if report: - # 2. Run the report. - report_file = run_report(service, profile_id, report['id']) - - # 3. Wait for the report file to be ready. - wait_for_report_file(service, report['id'], report_file['id']) - else: - print 'No report found for profile ID %d.\n' % profile_id - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def find_report(service, profile_id): - """Finds a report to run.""" - target = None - - # Construct the request. - request = service.reports().list(profileId=profile_id) - - while True: - response = request.execute() - - for report in response['items']: - if is_target_report(report): - target = report - break - - if not target and response['items'] and response['nextPageToken']: - request = service.reports().list_next(request, response) - else: - break - - if target: - print 'Found report %s with name "%s".' % (target['id'], target['name']) - return target - - print 'Unable to find report for profile ID %d.' % profile_id - return None - - -def is_target_report(report): - # Provide custom validation logic here. - # For example purposes, any report is considered valid. - return report is not None - - -def run_report(service, profile_id, report_id): - """Runs the report.""" - # Run the report. - report_file = service.reports().run( - profileId=profile_id, reportId=report_id).execute() - - print 'Running report %s, current file status is %s.' % ( - report_id, report_file['status']) - return report_file - - -def wait_for_report_file(service, report_id, file_id): - """Waits for the report file to finish processing.""" - # Wait for the report file to finish processing. - # An exponential backoff strategy is used to conserve request quota. - sleep = 0 - start_time = time.time() - while True: - report_file = service.files().get( - reportId=report_id, fileId=file_id).execute() - - status = report_file['status'] - if status == 'REPORT_AVAILABLE': - print 'File status is %s, ready to download.' % status - return - elif status != 'PROCESSING': - print 'File status is %s, processing failed.' % status - return - elif time.time() - start_time > MAX_RETRY_ELAPSED_TIME: - print 'File processing deadline exceeded.' - return - - sleep = next_sleep_interval(sleep) - print 'File status is %s, sleeping for %d seconds.' % (status, sleep) - time.sleep(sleep) - - -def next_sleep_interval(previous_sleep_interval): - """Calculates the next sleep interval based on the previous.""" - min_interval = previous_sleep_interval or MIN_RETRY_INTERVAL - max_interval = previous_sleep_interval * 3 or MIN_RETRY_INTERVAL - return min(MAX_RETRY_INTERVAL, random.randint(min_interval, max_interval)) - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_ads.py b/python/v4/get_ads.py deleted file mode 100755 index a7d38ee..0000000 --- a/python/v4/get_ads.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all active ads your DFA user profile can see. - -Only name and ID are returned. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up ads for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.ads().list(profileId=profile_id, active=True) - - while True: - # Execute request and print response. - response = request.execute() - - for ad in response['ads']: - print 'Found ad with ID %s and name "%s".' % (ad['id'], ad['name']) - - if response['ads'] and response['nextPageToken']: - request = service.ads().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_advertiser_groups.py b/python/v4/get_advertiser_groups.py deleted file mode 100644 index c69c636..0000000 --- a/python/v4/get_advertiser_groups.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all advertiser groups for a specified user profile.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to list activity groups for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.advertiserGroups().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for group in response['advertiserGroups']: - print ('Found advertiser group with ID %s and name "%s".' - % (group['id'], group['name'])) - - if response['advertiserGroups'] and response['nextPageToken']: - request = service.advertiserGroups().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_advertiser_landing_pages.py b/python/v4/get_advertiser_landing_pages.py deleted file mode 100644 index d183979..0000000 --- a/python/v4/get_advertiser_landing_pages.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2017 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all landing pages for the specified advertiser.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', - type=int, - help='The ID of the profile to look up advertiser landing pages for') -argparser.add_argument( - 'advertiser_id', - type=int, - help='The ID of the advertiser to look up landing pages for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - request = service.advertiserLandingPages().list( - profileId=profile_id, advertiserIds=[advertiser_id]) - - while True: - # Execute request and print response. - response = request.execute() - - for landing_page in response['landingPages']: - print('Found advertiser landing page with ID %s and name "%s".' % - (landing_page['id'], landing_page['name'])) - - if response['landingPages'] and response['nextPageToken']: - request = service.advertiserLandingPages().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_advertisers.py b/python/v4/get_advertisers.py deleted file mode 100755 index dffc246..0000000 --- a/python/v4/get_advertisers.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all advertisers. - -Only advertiser name, ID and floodlight config ID will be returned. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up advertisers for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.advertisers().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for advertiser in response['advertisers']: - print ('Found advertiser with ID %s and name "%s".' - % (advertiser['id'], advertiser['name'])) - - if response['advertisers'] and response['nextPageToken']: - request = service.advertisers().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_campaigns.py b/python/v4/get_campaigns.py deleted file mode 100644 index 28b471a..0000000 --- a/python/v4/get_campaigns.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all existing campaigns for the specified user profile.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up campaigns for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.campaigns().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for campaign in response['campaigns']: - print ('Found campaign with ID %s and name "%s".' - % (campaign['id'], campaign['name'])) - - if response['campaigns'] and response['nextPageToken']: - request = service.campaigns().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_change_logs_for_advertiser.py b/python/v4/get_change_logs_for_advertiser.py deleted file mode 100644 index 6fa696a..0000000 --- a/python/v4/get_change_logs_for_advertiser.py +++ /dev/null @@ -1,76 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays the change logs of a specified advertiser object. - -A similar pattern can be applied to get change logs for many other object -types. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up change logs for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to look up change logs for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - request = service.changeLogs().list( - profileId=profile_id, objectIds=[advertiser_id], - objectType='OBJECT_ADVERTISER') - - while True: - # Execute request and print response. - response = request.execute() - - for change_log in response['changeLogs']: - print( - '%s: Field "%s" from "%s" to "%s".' % - (change_log['action'], change_log['fieldName'], - change_log['oldValue'], change_log['newValue'])) - - if response['changeLogs'] and response['nextPageToken']: - request = service.changeLogs().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_compatible_fields.py b/python/v4/get_compatible_fields.py deleted file mode 100644 index 22fcf00..0000000 --- a/python/v4/get_compatible_fields.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to get the compatible fields for a report.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to use') -argparser.add_argument( - 'report_id', type=int, - help='The ID of the report to get compatible fields for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - report_id = flags.report_id - - try: - # Retrieve the specified report resource - report = service.reports().get( - profileId=profile_id, reportId=report_id).execute() - - compatible_fields_type = get_compatible_fields_type(report['type']) - - # Construct the request - request = service.reports().compatibleFields().query( - profileId=profile_id, body=report) - - # Execute the request and print response. - response = request.execute() - - compatible_fields = response[compatible_fields_type] - print_fields('Dimensions', compatible_fields['dimensions']) - print_fields('Metrics', compatible_fields['metrics']) - print_fields('Dimension Filters', - compatible_fields['dimensionFilters']) - print_fields('Pivoted Activity Metrics', - compatible_fields['pivotedActivityMetrics']) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def get_compatible_fields_type(report_type): - return { - 'CROSS_DIMENSION_REACH': 'crossDimensionReachReportCompatibleFields', - 'FLOODLIGHT': 'floodlightReportCompatibleFields', - 'PATH_TO_CONVERSION': 'pathToConversionReportCompatibleFields', - 'REACH': 'reachReportCompatibleFields' - }.get(report_type, 'reportCompatibleFields') - - -def print_fields(field_type, fields): - field_names = [field['name'] for field in fields] - print 'Compatible %s\n%s\n\n' % (field_type, ','.join(field_names)) - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_content_categories.py b/python/v4/get_content_categories.py deleted file mode 100644 index 2300efd..0000000 --- a/python/v4/get_content_categories.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all available content categories.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up content categories for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.contentCategories().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for category in response['contentCategories']: - print ('Found content category with ID %s and name "%s".' - % (category['id'], category['name'])) - - if response['contentCategories'] and response['nextPageToken']: - request = service.contentCategories().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_creative_field_values.py b/python/v4/get_creative_field_values.py deleted file mode 100644 index c8cd19c..0000000 --- a/python/v4/get_creative_field_values.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all creative fields.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to get creative field values for') -argparser.add_argument( - 'field_id', type=int, - help='The ID of the creative field to get values for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - field_id = flags.field_id - - try: - # Construct the request. - request = service.creativeFieldValues().list( - profileId=profile_id, creativeFieldId=field_id) - - while True: - # Execute request and print response. - response = request.execute() - - for value in response['creativeFieldValues']: - print ('Found creative field value with ID %s and value "%s".' - % (value['id'], value['value'])) - - if response['creativeFieldValues'] and response['nextPageToken']: - request = service.creativeFieldValues().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_creative_fields.py b/python/v4/get_creative_fields.py deleted file mode 100644 index 7493dfd..0000000 --- a/python/v4/get_creative_fields.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all creative fields.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to get creative fields for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.creativeFields().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for field in response['creativeFields']: - print ('Found creative field with ID %s and name "%s".' - % (field['id'], field['name'])) - - if response['creativeFields'] and response['nextPageToken']: - request = service.creativeFields().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_creative_groups.py b/python/v4/get_creative_groups.py deleted file mode 100644 index 6a39896..0000000 --- a/python/v4/get_creative_groups.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all creative groups.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to get creative groups for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.creativeGroups().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for group in response['creativeGroups']: - print ('Found creative group with ID %s and name "%s".' - % (group['id'], group['name'])) - - if response['creativeGroups'] and response['nextPageToken']: - request = service.advertisers().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_creatives.py b/python/v4/get_creatives.py deleted file mode 100644 index 0d97fed..0000000 --- a/python/v4/get_creatives.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all existing active creatives for a given advertiser. - -To get an advertiser ID, run get_advertisers.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up creatives for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to look up creatives for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - request = service.creatives().list( - profileId=profile_id, active=True, advertiserId=advertiser_id) - - while True: - # Execute request and print response. - response = request.execute() - - for creative in response['creatives']: - print ('Found %s creative with ID %s and name "%s".' - % (creative['type'], creative['id'], creative['name'])) - - if response['creatives'] and response['nextPageToken']: - request = service.creatives().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_dimension_values.py b/python/v4/get_dimension_values.py deleted file mode 100644 index f17f3ee..0000000 --- a/python/v4/get_dimension_values.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to get all dimension values for a dimension.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to get a report for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Create the dimension to query - dimension = { - 'dimensionName': 'advertiser', - 'startDate': '2012-01-01', - 'endDate': '2013-12-31' - } - - # Construct the request. - request = service.dimensionValues().query( - profileId=profile_id, body=dimension) - - while True: - # Execute request and print response. - response = request.execute() - - for value in response['items']: - print ('Found dimension value with ID %s and value "%s".' - % (value['id'], value['value'])) - - if response['items'] and response['nextPageToken']: - request = service.dimensionValues().query_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_files.py b/python/v4/get_files.py deleted file mode 100644 index c2c96ad..0000000 --- a/python/v4/get_files.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to get a list of all the files for a profile.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to use') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct a get request for the specified profile. - request = service.files().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for report_file in response['items']: - print ('File with ID %s and file name "%s" has status "%s".' - % (report_file['id'], report_file['fileName'], - report_file['status'])) - - if response['items'] and response['nextPageToken']: - request = service.files().list_next(request, response) - else: - break - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_floodlight_activities.py b/python/v4/get_floodlight_activities.py deleted file mode 100644 index c7ffa6f..0000000 --- a/python/v4/get_floodlight_activities.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays floodlight activities for a given advertiser. - -To create an advertiser, run create_advertiser.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to list activities for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to list activities for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - request = service.floodlightActivities().list( - profileId=profile_id, advertiserId=advertiser_id) - - while True: - # Execute request and print response. - response = request.execute() - - for activity in response['floodlightActivities']: - print ('Found floodlight activity with ID %s and name "%s".' - % (activity['id'], activity['name'])) - - if response['floodlightActivities'] and response['nextPageToken']: - request = service.floodlightActivities().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_floodlight_activity_groups.py b/python/v4/get_floodlight_activity_groups.py deleted file mode 100644 index ac17db7..0000000 --- a/python/v4/get_floodlight_activity_groups.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays floodlight activity groups for a given advertiser. - -To create an advertiser, run create_advertiser.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to list activity groups for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to list activity groups for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - request = service.floodlightActivityGroups().list( - profileId=profile_id, advertiserId=advertiser_id) - - # Execute request and print response. - response = request.execute() - - for group in response['floodlightActivityGroups']: - print ('Found floodlight activity group with ID %s and name "%s".' - % (group['id'], group['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_placement_strategies.py b/python/v4/get_placement_strategies.py deleted file mode 100644 index 3999316..0000000 --- a/python/v4/get_placement_strategies.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all available placement strategies.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up placement strategies for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.placementStrategies().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for strategy in response['placementStrategies']: - print ('Found placement strategy with ID %s and name "%s".' - % (strategy['id'], strategy['name'])) - - if response['placementStrategies'] and response['nextPageToken']: - request = service.placementStrategies().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_placements.py b/python/v4/get_placements.py deleted file mode 100644 index 909d01e..0000000 --- a/python/v4/get_placements.py +++ /dev/null @@ -1,65 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all available placements.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up placements for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.placements().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for placement in response['placements']: - print ('Found placement with ID %s and name "%s" for campaign "%s".' - % (placement['id'], placement['name'], - placement['campaignId'])) - - if response['placements'] and response['nextPageToken']: - request = service.placements().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_remarketing_lists.py b/python/v4/get_remarketing_lists.py deleted file mode 100644 index 59ee99b..0000000 --- a/python/v4/get_remarketing_lists.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Displays all remarketing lists owned by the specified advertiser. - -Note: the RemarketingLists resource will only return lists owned by the -specified advertiser. To see all lists that can be used for targeting ads -(including those shared from other accounts or advertisers), use the -TargetableRemarketingLists resource instead. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up remarketing lists for') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to look up remarketing lists for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = flags.advertiser_id - - try: - # Construct the request. - request = service.remarketingLists().list( - profileId=profile_id, advertiserId=advertiser_id) - - while True: - # Execute request and print response. - response = request.execute() - - for remarketing_list in response['remarketingLists']: - print ('Found remarketing list with ID %s and name "%s."' - % (remarketing_list['id'], remarketing_list['name'])) - - if response['remarketingLists'] and response['nextPageToken']: - request = service.remarketingLists().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_report_files.py b/python/v4/get_report_files.py deleted file mode 100644 index f7b839d..0000000 --- a/python/v4/get_report_files.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to get a list of all the files for a report.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to use') -argparser.add_argument( - 'report_id', type=int, - help='The ID of the report to list files for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - report_id = flags.report_id - - try: - # Construct a get request for the specified report. - request = service.reports().files().list( - profileId=profile_id, reportId=report_id) - - while True: - # Execute request and print response. - response = request.execute() - - for report_file in response['items']: - print ('Report file with ID %s and file name "%s" has status %s.' - % (report_file['id'], report_file['fileName'], - report_file['status'])) - - if response['items'] and response['nextPageToken']: - request = service.reports().files().list_next(request, response) - else: - break - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_reports.py b/python/v4/get_reports.py deleted file mode 100644 index 3c15b95..0000000 --- a/python/v4/get_reports.py +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to get a list of all reports.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to list reports for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.reports().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for report in response['items']: - print ('Found %s report with ID %s and name "%s".' - % (report['type'], report['id'], report['name'])) - - if response['items'] and response['nextPageToken']: - request = service.reports().list_next(request, response) - else: - break - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_sites.py b/python/v4/get_sites.py deleted file mode 100644 index b3720e5..0000000 --- a/python/v4/get_sites.py +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example lists all existing sites.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up sites for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.sites().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for site in response['sites']: - print ('Found site with ID %s and key name "%s".' - % (site['id'], site['keyName'])) - - if response['sites'] and response['nextPageToken']: - request = service.sites().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_size.py b/python/v4/get_size.py deleted file mode 100644 index a09f47a..0000000 --- a/python/v4/get_size.py +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all sizes for a given width and height.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up sizes for') -argparser.add_argument( - 'height', type=int, - help='Width of the size to look up') -argparser.add_argument( - 'width', type=int, - help='Height of the size to look up') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - height = flags.height - width = flags.width - - try: - # Construct the request. - request = service.sizes().list( - profileId=profile_id, height=height, width=width) - - # Execute request and print response. - result = request.execute() - - for size in result['sizes']: - print 'Found size with ID %s.' % (size['id']) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_subaccounts.py b/python/v4/get_subaccounts.py deleted file mode 100644 index d1f4c9b..0000000 --- a/python/v4/get_subaccounts.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all subaccounts. - -Note that the permissions assigned to a subaccount are not returned in a -human-readable format with this example. Run get_available_permissions.py to -see what permissions are available on a subaccount. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up sites for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Construct the request. - request = service.subaccounts().list(profileId=profile_id) - - while True: - # Execute request and print response. - response = request.execute() - - for subaccount in response['subaccounts']: - print ('Found subaccount with ID %s and name "%s".' - % (subaccount['id'], subaccount['name'])) - - if response['subaccounts'] and response['nextPageToken']: - request = service.subaccounts().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_targeting_templates.py b/python/v4/get_targeting_templates.py deleted file mode 100644 index a138fc8..0000000 --- a/python/v4/get_targeting_templates.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example retrieves all targeting templates for your DCM user profile. - -Displays name, ID, and advertiser ID for each targeting template found. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up targeting templates for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Limit the fields returned - fields = 'nextPageToken,targetingTemplates(advertiserId,id,name)' - - # Construct the request. - request = service.targetingTemplates().list(profileId=profile_id, - fields=fields) - - while True: - # Execute request and print response. - response = request.execute() - - for template in response['targetingTemplates']: - print ('Found targeting template with ID %s and name "%s" associated ' - 'with advertiser ID %s.' % (template['id'], template['name'], - template['advertiserId'])) - - if response['targetingTemplates'] and response['nextPageToken']: - request = service.targetingTemplates().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_user_role_permissions.py b/python/v4/get_user_role_permissions.py deleted file mode 100644 index 8ad2a02..0000000 --- a/python/v4/get_user_role_permissions.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all of the available subaccount permissions. - -To get a subaccount ID, run get_subaccounts.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to list permissions for') -argparser.add_argument( - 'subaccount_id', type=int, - help='The ID of the subaccount to list permissions for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - subaccount_id = flags.subaccount_id - - try: - # Construct and execute the subaccount request. - request = service.subaccounts().get( - profileId=profile_id, id=subaccount_id) - - subaccount = request.execute() - - # Construct the user role permissions request. - request = service.userRolePermissions().list( - profileId=profile_id, ids=subaccount['availablePermissionIds']) - - # Execute request and print response. - result = request.execute() - - for permission in result['userRolePermissions']: - print ('Found user role permission with ID %s and name "%s".' - % (permission['id'], permission['name'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_user_roles.py b/python/v4/get_user_roles.py deleted file mode 100644 index cb78b36..0000000 --- a/python/v4/get_user_roles.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example displays all user roles. - -The output is limited to include only ID, name, account ID and subaccount ID. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to look up sites for') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - - try: - # Limit the fields returned - fields = 'nextPageToken,userRoles(accountId,id,name,subaccountId)' - - # Construct the request. - request = service.userRoles().list(profileId=profile_id, fields=fields) - - while True: - # Execute request and print response. - response = request.execute() - - for user_role in response['userRoles']: - print ('Found user role with ID %s and name "%s".' - % (user_role['id'], user_role['name'])) - - if response['userRoles'] and response['nextPageToken']: - request = service.userRoles().list_next(request, response) - else: - break - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/get_userprofiles.py b/python/v4/get_userprofiles.py deleted file mode 100644 index d029d85..0000000 --- a/python/v4/get_userprofiles.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to get a list of all user profiles.""" - -import sys - -import dfareporting_utils -from oauth2client import client - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - try: - # Construct the request. - request = service.userProfiles().list() - - # Execute request and print response. - response = request.execute() - - for profile in response['items']: - print ('Found user profile with ID %s and name "%s" for account %s.' - % (profile['profileId'], profile['userName'], - profile['accountId'])) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/insert_offline_mobile_conversion.py b/python/v4/insert_offline_mobile_conversion.py deleted file mode 100644 index d659e0d..0000000 --- a/python/v4/insert_offline_mobile_conversion.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Inserts an offline conversion attributed to a mobile device ID.""" - -import argparse -import sys -import time - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement for') -argparser.add_argument( - 'mobile_device_id', - help='The ID of the mobile device to attribute the conversion to') -argparser.add_argument( - 'floodlight_activity_id', type=int, - help='The ID of Floodlight activity this conversion is associated with') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - floodlight_activity_id = flags.floodlight_activity_id - mobile_device_id = flags.mobile_device_id - - try: - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.floodlightActivities().get( - profileId=profile_id, id=floodlight_activity_id).execute() - floodlight_config_id = floodlight_activity['floodlightConfigurationId'] - - current_time_in_micros = int(time.time() * 1000000) - - # Construct the conversion. - conversion = { - 'floodlightActivityId': floodlight_activity_id, - 'floodlightConfigurationId': floodlight_config_id, - 'ordinal': current_time_in_micros, - 'mobileDeviceId': mobile_device_id, - 'timestampMicros': current_time_in_micros - } - - # Insert the conversion. - request_body = {'conversions': [conversion]} - request = service.conversions().batchinsert(profileId=profile_id, - body=request_body) - response = request.execute() - - if not response['hasFailures']: - print ('Successfully inserted conversion for mobile device ID %s.' - % mobile_device_id) - else: - print ('Error(s) inserting conversion for mobile device ID %s.' - % mobile_device_id) - - status = response['status'][0] - for error in status['errors']: - print '\t[%s]: %s' % (error['code'], error['message']) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/insert_offline_user_conversion.py b/python/v4/insert_offline_user_conversion.py deleted file mode 100644 index 974c3f1..0000000 --- a/python/v4/insert_offline_user_conversion.py +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2016 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Inserts an offline conversion attributed to an encrypted user ID.""" - -import argparse -import sys -import time - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to add a placement for') -argparser.add_argument( - 'encrypted_user_id', - help='The encrypted user ID to attribute the conversion to') -argparser.add_argument( - 'encryption_source', - help='The source of the encrypted user ID') -argparser.add_argument( - 'encryption_entity_id', type=int, - help='The ID of the entity used to encrypt the supplied user ID') -argparser.add_argument( - 'encryption_entity_type', - help='The type of the entity used to encrypt the supplied user ID') -argparser.add_argument( - 'floodlight_activity_id', type=int, - help='The ID of Floodlight activity this conversion is associated with') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - encrypted_user_id = flags.encrypted_user_id - encryption_entity_id = flags.encryption_entity_id - encryption_entity_type = flags.encryption_entity_type - encryption_source = flags.encryption_source - floodlight_activity_id = flags.floodlight_activity_id - - try: - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.floodlightActivities().get( - profileId=profile_id, id=floodlight_activity_id).execute() - floodlight_config_id = floodlight_activity['floodlightConfigurationId'] - - current_time_in_micros = int(time.time() * 1000000) - - # Construct the conversion. - conversion = { - 'encryptedUserId': encrypted_user_id, - 'floodlightActivityId': floodlight_activity_id, - 'floodlightConfigurationId': floodlight_config_id, - 'ordinal': current_time_in_micros, - 'timestampMicros': current_time_in_micros - } - - # Construct the encryption info. - encryption_info = { - 'encryptionEntityId': encryption_entity_id, - 'encryptionEntityType': encryption_entity_type, - 'encryptionSource': encryption_source - } - - # Insert the conversion. - request_body = { - 'conversions': [conversion], - 'encryptionInfo': encryption_info - } - request = service.conversions().batchinsert(profileId=profile_id, - body=request_body) - response = request.execute() - - if not response['hasFailures']: - print ('Successfully inserted conversion for encrypted user ID %s.' - % encrypted_user_id) - else: - print ('Error(s) inserting conversion for encrypted user ID %s.' - % encrypted_user_id) - - status = response['status'][0] - for error in status['errors']: - print '\t[%s]: %s' % (error['code'], error['message']) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/run_report.py b/python/v4/run_report.py deleted file mode 100644 index cc83059..0000000 --- a/python/v4/run_report.py +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example illustrates how to run a report.""" - -import argparse -import random -import sys -import time - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to use') -argparser.add_argument( - 'report_id', type=int, - help='The ID of the report to run') - -# The following values control retry behavior while the report is processing. -# Minimum amount of time between polling requests. Defaults to 10 seconds. -MIN_RETRY_INTERVAL = 10 -# Maximum amount of time between polling requests. Defaults to 10 minutes. -MAX_RETRY_INTERVAL = 10 * 60 -# Maximum amount of time to spend polling. Defaults to 1 hour. -MAX_RETRY_ELAPSED_TIME = 60 * 60 - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - report_id = flags.report_id - - try: - # Run the report. - report_file = service.reports().run(profileId=profile_id, - reportId=report_id).execute() - print 'File with ID %s has been created.' % report_file['id'] - - # Wait for the report file to finish processing. - # An exponential backoff strategy is used to conserve request quota. - sleep = 0 - start_time = time.time() - while True: - report_file = service.files().get(reportId=report_id, - fileId=report_file['id']).execute() - - status = report_file['status'] - if status == 'REPORT_AVAILABLE': - print 'File status is %s, ready to download.' % status - return - elif status != 'PROCESSING': - print 'File status is %s, processing failed.' % status - return - elif time.time() - start_time > MAX_RETRY_ELAPSED_TIME: - print 'File processing deadline exceeded.' - return - - sleep = next_sleep_interval(sleep) - print 'File status is %s, sleeping for %d seconds.' % (status, sleep) - time.sleep(sleep) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -def next_sleep_interval(previous_sleep_interval): - """Calculates the next sleep interval based on the previous.""" - min_interval = previous_sleep_interval or MIN_RETRY_INTERVAL - max_interval = previous_sleep_interval * 3 or MIN_RETRY_INTERVAL - return min(MAX_RETRY_INTERVAL, random.randint(min_interval, max_interval)) - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/share_remarketing_list_to_advertiser.py b/python/v4/share_remarketing_list_to_advertiser.py deleted file mode 100644 index 964bfc4..0000000 --- a/python/v4/share_remarketing_list_to_advertiser.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Shares an existing remarketing list with the specified advertiser.""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, - help='The ID of the profile to share remarketing lists as') -argparser.add_argument( - 'advertiser_id', type=int, - help='The ID of the advertiser to share the remarketing list with') -argparser.add_argument( - 'remarketing_list_id', type=int, - help='The ID of the remarketing list to share') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - advertiser_id = str(flags.advertiser_id) - list_id = flags.remarketing_list_id - - try: - # Load the existing share info. - share = service.remarketingListShares().get( - profileId=profile_id, remarketingListId=list_id).execute() - - share['sharedAdvertiserIds'] = share.get('sharedAdvertiserIds', []) - - if advertiser_id not in share['sharedAdvertiserIds']: - share['sharedAdvertiserIds'].append(advertiser_id) - - # Update the share info with the newly added advertiser ID. - response = service.remarketingListShares().update( - profileId=profile_id, body=share).execute() - - print ('Remarketing list %s is now shared to advertiser ID(s): %s.' - % (list_id, ','.join(response['sharedAdvertiserIds']))) - else: - print ('Remarketing list %s is already shared to advertiser %s' - % (list_id, advertiser_id)) - - except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/target_ad_to_remarketing_list.py b/python/v4/target_ad_to_remarketing_list.py deleted file mode 100644 index 658e252..0000000 --- a/python/v4/target_ad_to_remarketing_list.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2015 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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 example targets an ad to a remarketing list. - -The first targetable remarketing list, either owned by or shared to the ad's -advertiser, will be used. To create a remarketing list, see -create_remarketing_list.py. To share a remarketing list with the ad's -advertiser, see share_remarketing_list_to_advertiser.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', type=int, help='The ID of the profile to use for targeting') -argparser.add_argument('ad_id', type=int, help='The ID of the ad to target') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - ad_id = flags.ad_id - - try: - # Retrieve the ad. - ad = service.ads().get(profileId=profile_id, id=ad_id).execute() - - # Retrieve a single targetable remarketing list for the ad. - lists = service.targetableRemarketingLists().list( - profileId=profile_id, advertiserId=ad['advertiserId'], - maxResults=1).execute() - - if lists['targetableRemarketingLists']: - remarketing_list = lists['targetableRemarketingLists'][0] - - # Update the ad with a list targeting expression - ad['remarketingListExpression'] = { - 'expression': remarketing_list['id'] - } - response = service.ads().update(profileId=profile_id, body=ad).execute() - - print('Ad %s updated to use remarketing list expression: "%s".' - % (response['id'], - response['remarketingListExpression']['expression'])) - else: - print 'No targetable remarketing lists found for ad with ID %d.' % ad_id - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/update_offline_mobile_conversion.py b/python/v4/update_offline_mobile_conversion.py deleted file mode 100644 index 9fd2736..0000000 --- a/python/v4/update_offline_mobile_conversion.py +++ /dev/null @@ -1,116 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2017 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Updates an offline conversion attributed to a mobile device ID. - -To create a conversion attributed to a mobile device ID, run -insert_offline_mobile_conversion.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', - type=int, - help='The ID of the profile to update a conversion for') - -# Values that identify the existing conversion. -argparser.add_argument( - 'mobile_device_id', - help='The ID of the mobile device the conversion is attributed to.') -argparser.add_argument( - 'floodlight_activity_id', - type=int, - help='The ID of Floodlight activity the conversion is associated with') -argparser.add_argument('ordinal', help='The ordinal of the conversion.') -argparser.add_argument( - 'timestamp', type=int, help='The timestamp of the conversion.') - -# Values to update for the specified conversion. -argparser.add_argument( - 'new_quantity', - type=int, - help='The new quantity to set for the conversion.') -argparser.add_argument( - 'new_value', type=int, help='The new value to set for the conversion.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - floodlight_activity_id = flags.floodlight_activity_id - mobile_device_id = flags.mobile_device_id - ordinal = flags.ordinal - timestamp = flags.timestamp - new_quantity = flags.new_quantity - new_value = flags.new_value - - try: - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.floodlightActivities().get( - profileId=profile_id, id=floodlight_activity_id).execute() - floodlight_config_id = floodlight_activity['floodlightConfigurationId'] - - # Construct the conversion object with values that identify the conversion - # to update. - conversion = { - 'floodlightActivityId': floodlight_activity_id, - 'floodlightConfigurationId': floodlight_config_id, - 'ordinal': ordinal, - 'mobileDeviceId': mobile_device_id, - 'timestampMicros': timestamp - } - - # Set the fields to be updated. These fields are required; to preserve a - # value from the existing conversion, it must be copied over manually. - conversion['quantity'] = new_quantity - conversion['value'] = new_value - - # Update the conversion. - request_body = {'conversions': [conversion]} - request = service.conversions().batchupdate( - profileId=profile_id, body=request_body) - response = request.execute() - - if not response['hasFailures']: - print('Successfully updated conversion for mobile device ID %s.' % - mobile_device_id) - else: - print('Error(s) updating conversion for mobile device ID %s.' % - mobile_device_id) - - status = response['status'][0] - for error in status['errors']: - print '\t[%s]: %s' % (error['code'], error['message']) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv) diff --git a/python/v4/update_offline_user_conversion.py b/python/v4/update_offline_user_conversion.py deleted file mode 100644 index e7b9fff..0000000 --- a/python/v4/update_offline_user_conversion.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/python -# -# Copyright 2017 Google Inc. All Rights Reserved. -# -# 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 -# -# http://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. - -"""Updates an offline conversion attributed to an encrypted user ID. - -To create a conversion attributed to an encrypted user ID, run -insert_offline_user_conversion.py. -""" - -import argparse -import sys - -import dfareporting_utils -from oauth2client import client - -# Declare command-line flags. -argparser = argparse.ArgumentParser(add_help=False) -argparser.add_argument( - 'profile_id', - type=int, - help='The ID of the profile to update a conversion for') - -# Values that specify how the existing conversion is encrypted. -argparser.add_argument( - 'encrypted_user_id', - help='The encrypted user ID the conversion is attributed to') -argparser.add_argument( - 'encryption_source', help='The source of the encrypted user ID') -argparser.add_argument( - 'encryption_entity_id', - type=int, - help='The ID of the entity used to encrypt the supplied user ID') -argparser.add_argument( - 'encryption_entity_type', - help='The type of the entity used to encrypt the supplied user ID') - -# Values that identify the existing conversion. -argparser.add_argument( - 'floodlight_activity_id', - type=int, - help='The ID of Floodlight activity this conversion is associated with') -argparser.add_argument('ordinal', help='The ordinal of the conversion.') -argparser.add_argument( - 'timestamp', type=int, help='The timestamp of the conversion.') - -# Values to update for the specified conversion. -argparser.add_argument( - 'new_quantity', - type=int, - help='The new quantity to set for the conversion.') -argparser.add_argument( - 'new_value', type=int, help='The new value to set for the conversion.') - - -def main(argv): - # Retrieve command line arguments. - flags = dfareporting_utils.get_arguments(argv, __doc__, parents=[argparser]) - - # Authenticate and construct service. - service = dfareporting_utils.setup(flags) - - profile_id = flags.profile_id - encrypted_user_id = flags.encrypted_user_id - encryption_entity_id = flags.encryption_entity_id - encryption_entity_type = flags.encryption_entity_type - encryption_source = flags.encryption_source - floodlight_activity_id = flags.floodlight_activity_id - ordinal = flags.ordinal - timestamp = flags.timestamp - new_quantity = flags.new_quantity - new_value = flags.new_value - - try: - # Look up the Floodlight configuration ID based on activity ID. - floodlight_activity = service.floodlightActivities().get( - profileId=profile_id, id=floodlight_activity_id).execute() - floodlight_config_id = floodlight_activity['floodlightConfigurationId'] - - # Construct the conversion object with values that identify the conversion - # to update. - conversion = { - 'encryptedUserId': encrypted_user_id, - 'floodlightActivityId': floodlight_activity_id, - 'floodlightConfigurationId': floodlight_config_id, - 'ordinal': ordinal, - 'timestampMicros': timestamp - } - - # Set the fields to be updated. These fields are required; to preserve a - # value from the existing conversion, it must be copied over manually. - conversion['quantity'] = new_quantity - conversion['value'] = new_value - - # Construct the encryption info. - encryption_info = { - 'encryptionEntityId': encryption_entity_id, - 'encryptionEntityType': encryption_entity_type, - 'encryptionSource': encryption_source - } - - # Update the conversion. - request_body = { - 'conversions': [conversion], - 'encryptionInfo': encryption_info - } - request = service.conversions().batchupdate( - profileId=profile_id, body=request_body) - response = request.execute() - - if not response['hasFailures']: - print('Successfully updated conversion for encrypted user ID %s.' % - encrypted_user_id) - else: - print('Error(s) updating conversion for encrypted user ID %s.' % - encrypted_user_id) - - status = response['status'][0] - for error in status['errors']: - print '\t[%s]: %s' % (error['code'], error['message']) - - except client.AccessTokenRefreshError: - print('The credentials have been revoked or expired, please re-run the ' - 'application to re-authorize') - - -if __name__ == '__main__': - main(sys.argv)