1#!/usr/bin/python 2# 3# Copyright 2014 Google Inc. All Rights Reserved. 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17"""This example gets all the saved reports for the logged 18in user's default account. 19 20Tags: savedreports.list 21""" 22from __future__ import print_function 23 24__author__ = 'sgomes@google.com (Sérgio Gomes)' 25 26import sys 27 28from googleapiclient import sample_tools 29from oauth2client import client 30 31MAX_PAGE_SIZE = 50 32 33 34def main(argv): 35 # Authenticate and construct service. 36 service, flags = sample_tools.init( 37 argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[], 38 scope='https://www.googleapis.com/auth/adexchange.seller.readonly') 39 40 try: 41 # Retrieve ad client list in pages and display data as we receive it. 42 request = service.reports().saved().list(maxResults=MAX_PAGE_SIZE) 43 44 while request is not None: 45 result = request.execute() 46 saved_reports = result['items'] 47 for saved_report in saved_reports: 48 print(('Saved report with ID "%s" and name "%s" was found.' 49 % (saved_report['id'], saved_report['name']))) 50 51 request = service.reports().saved().list_next(request, result) 52 53 except client.AccessTokenRefreshError: 54 print ('The credentials have been revoked or expired, please re-run the ' 55 'application to re-authorize') 56 57if __name__ == '__main__': 58 main(sys.argv) 59