From 8c395344255c5df7dcbc897985676e2cebfb3af0 Mon Sep 17 00:00:00 2001 From: Jose Alcerreca Date: Wed, 19 Jun 2013 16:32:15 +0100 Subject: [PATCH] Updated AdSense Management API samples to V1.3 Reviewed in https://codereview.appspot.com/10382043/ --- samples/adsense/generate_report.py | 4 +- .../adsense/generate_report_with_paging.py | 2 +- samples/adsense/get_account_tree.py | 4 +- samples/adsense/get_all_accounts.py | 2 +- samples/adsense/get_all_ad_clients.py | 4 +- .../adsense/get_all_ad_clients_for_account.py | 4 +- samples/adsense/get_all_ad_units.py | 4 +- .../get_all_ad_units_for_custom_channel.py | 6 +- samples/adsense/get_all_alerts.py | 55 +++++++++++++++++++ samples/adsense/get_all_custom_channels.py | 8 +-- .../get_all_custom_channels_for_ad_unit.py | 6 +- samples/adsense/get_all_dimensions.py | 55 +++++++++++++++++++ samples/adsense/get_all_metrics.py | 55 +++++++++++++++++++ samples/adsense/get_all_saved_ad_styles.py | 2 +- samples/adsense/get_all_saved_reports.py | 2 +- samples/adsense/get_all_url_channels.py | 5 +- 16 files changed, 190 insertions(+), 28 deletions(-) create mode 100644 samples/adsense/get_all_alerts.py create mode 100644 samples/adsense/get_all_dimensions.py create mode 100644 samples/adsense/get_all_metrics.py diff --git a/samples/adsense/generate_report.py b/samples/adsense/generate_report.py index 2c2f8c9..b6619d8 100644 --- a/samples/adsense/generate_report.py +++ b/samples/adsense/generate_report.py @@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py. Tags: reports.generate """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -40,7 +40,7 @@ argparser.add_argument('report_id', def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') # Process flags and read their values. diff --git a/samples/adsense/generate_report_with_paging.py b/samples/adsense/generate_report_with_paging.py index 965b069..ca69763 100644 --- a/samples/adsense/generate_report_with_paging.py +++ b/samples/adsense/generate_report_with_paging.py @@ -46,7 +46,7 @@ argparser.add_argument('ad_client_id', def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') ad_client_id = flags.ad_client_id diff --git a/samples/adsense/get_account_tree.py b/samples/adsense/get_account_tree.py index a976b66..83d99c8 100644 --- a/samples/adsense/get_account_tree.py +++ b/samples/adsense/get_account_tree.py @@ -21,7 +21,7 @@ This includes the full tree of sub-accounts. Tags: accounts.get """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -38,7 +38,7 @@ argparser.add_argument('account_id', def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') # Process flags and read their values. diff --git a/samples/adsense/get_all_accounts.py b/samples/adsense/get_all_accounts.py index d53a0c8..ab0328e 100644 --- a/samples/adsense/get_all_accounts.py +++ b/samples/adsense/get_all_accounts.py @@ -32,7 +32,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], scope='https://www.googleapis.com/auth/adsense.readonly') try: diff --git a/samples/adsense/get_all_ad_clients.py b/samples/adsense/get_all_ad_clients.py index 19fc527..ae76aa1 100644 --- a/samples/adsense/get_all_ad_clients.py +++ b/samples/adsense/get_all_ad_clients.py @@ -19,7 +19,7 @@ Tags: adclients.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import sys @@ -32,7 +32,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], scope='https://www.googleapis.com/auth/adsense.readonly') try: diff --git a/samples/adsense/get_all_ad_clients_for_account.py b/samples/adsense/get_all_ad_clients_for_account.py index 87f29eb..c9bcb5a 100644 --- a/samples/adsense/get_all_ad_clients_for_account.py +++ b/samples/adsense/get_all_ad_clients_for_account.py @@ -19,7 +19,7 @@ Tags: accounts.adclients.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -38,7 +38,7 @@ argparser.add_argument('account_id', def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') account_id = flags.account_id diff --git a/samples/adsense/get_all_ad_units.py b/samples/adsense/get_all_ad_units.py index 28f7988..88f1486 100644 --- a/samples/adsense/get_all_ad_units.py +++ b/samples/adsense/get_all_ad_units.py @@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py. Tags: adunits.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -40,7 +40,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') ad_client_id = flags.ad_client_id diff --git a/samples/adsense/get_all_ad_units_for_custom_channel.py b/samples/adsense/get_all_ad_units_for_custom_channel.py index 02d1378..7ee629f 100644 --- a/samples/adsense/get_all_ad_units_for_custom_channel.py +++ b/samples/adsense/get_all_ad_units_for_custom_channel.py @@ -21,7 +21,7 @@ To get custom channels, run get_all_custom_channels.py. Tags: accounts.customchannels.adunits.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -34,7 +34,7 @@ argparser = argparse.ArgumentParser(add_help=False) argparser.add_argument('account_id', help='The ID of the account with the specified custom channel') argparser.add_argument('ad_client_id', - help='The ID of the ad client for which to generate a report') + help='The ID of the ad client with the specified custom channel') argparser.add_argument('custom_channel_id', help='The ID of the custom channel for which to get ad units') @@ -44,7 +44,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') # Process flags and read their values. diff --git a/samples/adsense/get_all_alerts.py b/samples/adsense/get_all_alerts.py new file mode 100644 index 0000000..14a7164 --- /dev/null +++ b/samples/adsense/get_all_alerts.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# +# Copyright 2013 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. + +"""Gets all alerts available for the logged in user's default account. + +Tags: metadata.alerts.list +""" + +__author__ = 'jalc@google.com (Jose Alcerreca)' + +import argparse +import sys + +from apiclient import sample_tools +from oauth2client import client + + +def main(argv): + # Authenticate and construct service. + service, flags = sample_tools.init( + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], + scope='https://www.googleapis.com/auth/adsense.readonly') + + try: + # Retrieve alerts list in pages and display data as we receive it. + request = service.alerts().list() + + if request is not None: + result = request.execute() + if 'items' in result: + alerts = result['items'] + for alert in alerts: + print ('Alert id "%s" with severity "%s" and type "%s" was found. ' + % (alert['id'], alert['severity'], alert['type'])) + else: + print 'No alerts found!' + 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/samples/adsense/get_all_custom_channels.py b/samples/adsense/get_all_custom_channels.py index e10a85f..a9a9b9a 100644 --- a/samples/adsense/get_all_custom_channels.py +++ b/samples/adsense/get_all_custom_channels.py @@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py. Tags: customchannels.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -40,7 +40,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') ad_client_id = flags.ad_client_id @@ -54,8 +54,8 @@ def main(argv): result = request.execute() custom_channels = result['items'] for custom_channel in custom_channels: - print ('Custom channel with code "%s" and name "%s" was found. ' - % (custom_channel['code'], custom_channel['name'])) + print ('Custom channel with id "%s" and name "%s" was found. ' + % (custom_channel['id'], custom_channel['name'])) if 'targetingInfo' in custom_channel: print ' Targeting info:' diff --git a/samples/adsense/get_all_custom_channels_for_ad_unit.py b/samples/adsense/get_all_custom_channels_for_ad_unit.py index 677c293..5064c01 100644 --- a/samples/adsense/get_all_custom_channels_for_ad_unit.py +++ b/samples/adsense/get_all_custom_channels_for_ad_unit.py @@ -22,8 +22,7 @@ get_all_ad_units.py. Tags: customchannels.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' - +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -49,7 +48,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') # Process flags and read their values. @@ -85,7 +84,6 @@ def main(argv): request = service.customchannels().list_next(request, result) except client.AccessTokenRefreshError: - print ('The credentials have been revoked or expired, please re-run the ' 'application to re-authorize') diff --git a/samples/adsense/get_all_dimensions.py b/samples/adsense/get_all_dimensions.py new file mode 100644 index 0000000..1d647a0 --- /dev/null +++ b/samples/adsense/get_all_dimensions.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# +# Copyright 2013 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. + +"""Gets all dimensions available for the logged in user's default account. + +Tags: metadata.dimensions.list +""" + +__author__ = 'jalc@google.com (Jose Alcerreca)' + +import argparse +import sys + +from apiclient import sample_tools +from oauth2client import client + + +def main(argv): + # Authenticate and construct service. + service, flags = sample_tools.init( + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], + scope='https://www.googleapis.com/auth/adsense.readonly') + + try: + # Retrieve metrics list in pages and display data as we receive it. + request = service.metadata().dimensions().list() + + if request is not None: + result = request.execute() + if 'items' in result: + dimensions = result['items'] + for dimension in dimensions: + print ('Dimension id "%s" for product(s): [%s] was found. ' + % (dimension['id'], ', '.join(dimension['supportedProducts']))) + else: + print 'No dimensions found!' + 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/samples/adsense/get_all_metrics.py b/samples/adsense/get_all_metrics.py new file mode 100644 index 0000000..ce1b7d3 --- /dev/null +++ b/samples/adsense/get_all_metrics.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +# +# Copyright 2013 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. + +"""Gets all metrics available for the logged in user's default account. + +Tags: metadata.metrics.list +""" + +__author__ = 'jalc@google.com (Jose Alcerreca)' + +import argparse +import sys + +from apiclient import sample_tools +from oauth2client import client + + +def main(argv): + # Authenticate and construct service. + service, flags = sample_tools.init( + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], + scope='https://www.googleapis.com/auth/adsense.readonly') + + try: + # Retrieve metrics list in pages and display data as we receive it. + request = service.metadata().metrics().list() + + if request is not None: + result = request.execute() + if 'items' in result: + metrics = result['items'] + for metric in metrics: + print ('Metric id "%s" for product(s): [%s] was found. ' + % (metric['id'], ', '.join(metric['supportedProducts']))) + else: + print 'No metrics found!' + 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/samples/adsense/get_all_saved_ad_styles.py b/samples/adsense/get_all_saved_ad_styles.py index f1f9b0c..961c125 100644 --- a/samples/adsense/get_all_saved_ad_styles.py +++ b/samples/adsense/get_all_saved_ad_styles.py @@ -33,7 +33,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], scope='https://www.googleapis.com/auth/adsense.readonly') try: diff --git a/samples/adsense/get_all_saved_reports.py b/samples/adsense/get_all_saved_reports.py index 65ab28d..a8fcc6a 100644 --- a/samples/adsense/get_all_saved_reports.py +++ b/samples/adsense/get_all_saved_reports.py @@ -33,7 +33,7 @@ MAX_PAGE_SIZE = 50 def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[], scope='https://www.googleapis.com/auth/adsense.readonly') try: diff --git a/samples/adsense/get_all_url_channels.py b/samples/adsense/get_all_url_channels.py index 3a8150b..5d2d3d1 100644 --- a/samples/adsense/get_all_url_channels.py +++ b/samples/adsense/get_all_url_channels.py @@ -21,7 +21,7 @@ To get ad clients, run get_all_ad_clients.py. Tags: urlchannels.list """ -__author__ = 'sergio.gomes@google.com (Sergio Gomes)' +__author__ = 'jalc@google.com (Jose Alcerreca)' import argparse import sys @@ -40,7 +40,7 @@ argparser.add_argument('ad_client_id', def main(argv): # Authenticate and construct service. service, flags = sample_tools.init( - argv, 'adsense', 'v1.2', __doc__, __file__, parents=[argparser], + argv, 'adsense', 'v1.3', __doc__, __file__, parents=[argparser], scope='https://www.googleapis.com/auth/adsense.readonly') ad_client_id = flags.ad_client_id @@ -52,7 +52,6 @@ def main(argv): while request is not None: result = request.execute() - custom_channels = result['items'] url_channels = result['items'] for url_channel in url_channels: