Home | History | Annotate | Download | only in adexchangeseller
      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 ad units in an ad client.
     18 
     19 To get ad clients, run get_all_ad_clients.py.
     20 
     21 Tags: adunits.list
     22 """
     23 from __future__ import print_function
     24 
     25 __author__ = 'sgomes (at] google.com (Srgio Gomes)'
     26 
     27 import argparse
     28 import sys
     29 
     30 from googleapiclient import sample_tools
     31 from oauth2client import client
     32 
     33 # Declare command-line flags.
     34 argparser = argparse.ArgumentParser(add_help=False)
     35 argparser.add_argument('ad_client_id',
     36     help='The ID of the ad client for which to generate a report')
     37 
     38 MAX_PAGE_SIZE = 50
     39 
     40 
     41 def main(argv):
     42   # Authenticate and construct service.
     43   service, flags = sample_tools.init(
     44       argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[argparser],
     45       scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
     46 
     47   ad_client_id = flags.ad_client_id
     48 
     49   try:
     50     # Retrieve ad unit list in pages and display data as we receive it.
     51     request = service.adunits().list(adClientId=ad_client_id,
     52         maxResults=MAX_PAGE_SIZE)
     53 
     54     while request is not None:
     55       result = request.execute()
     56       ad_units = result['items']
     57       for ad_unit in ad_units:
     58         print(('Ad unit with code "%s", name "%s" and status "%s" was found. ' %
     59                (ad_unit['code'], ad_unit['name'], ad_unit['status'])))
     60 
     61       request = service.adunits().list_next(request, result)
     62 
     63   except client.AccessTokenRefreshError:
     64     print ('The credentials have been revoked or expired, please re-run the '
     65            'application to re-authorize')
     66 
     67 if __name__ == '__main__':
     68   main(sys.argv)
     69