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 clients for the logged in user's account.
     18 
     19 Tags: adclients.list
     20 """
     21 from __future__ import print_function
     22 
     23 __author__ = 'sgomes (at] google.com (Srgio Gomes)'
     24 
     25 import sys
     26 
     27 from googleapiclient import sample_tools
     28 from oauth2client import client
     29 
     30 MAX_PAGE_SIZE = 50
     31 
     32 
     33 def main(argv):
     34   # Authenticate and construct service.
     35   service, flags = sample_tools.init(
     36       argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
     37       scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
     38 
     39   try:
     40     # Retrieve ad client list in pages and display data as we receive it.
     41     request = service.adclients().list(maxResults=MAX_PAGE_SIZE)
     42 
     43     while request is not None:
     44       result = request.execute()
     45       ad_clients = result['items']
     46       for ad_client in ad_clients:
     47         print(('Ad client for product "%s" with ID "%s" was found. '
     48                % (ad_client['productCode'], ad_client['id'])))
     49 
     50         print(('\tSupports reporting: %s' %
     51                (ad_client['supportsReporting'] and 'Yes' or 'No')))
     52 
     53       request = service.adclients().list_next(request, result)
     54 
     55   except client.AccessTokenRefreshError:
     56     print ('The credentials have been revoked or expired, please re-run the '
     57            'application to re-authorize')
     58 
     59 if __name__ == '__main__':
     60   main(sys.argv)
     61