• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 URL channels in an ad client.
18
19To get ad clients, run get_all_ad_clients.py.
20
21Tags: urlchannels.list
22"""
23from __future__ import print_function
24
25__author__ = 'sgomes@google.com (Sérgio Gomes)'
26
27import argparse
28import sys
29
30from googleapiclient import sample_tools
31from oauth2client import client
32
33MAX_PAGE_SIZE = 50
34
35# Declare command-line flags.
36argparser = argparse.ArgumentParser(add_help=False)
37argparser.add_argument('ad_client_id',
38    help='The ad client ID for which to get URL channels')
39
40
41def 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 URL channel list in pages and display data as we receive it.
51    request = service.urlchannels().list(adClientId=ad_client_id,
52        maxResults=MAX_PAGE_SIZE)
53
54    while request is not None:
55      result = request.execute()
56
57      url_channels = result['items']
58      for url_channel in url_channels:
59        print(('URL channel with URL pattern "%s" was found.'
60               % url_channel['urlPattern']))
61
62      request = service.customchannels().list_next(request, result)
63
64  except client.AccessTokenRefreshError:
65    print ('The credentials have been revoked or expired, please re-run the '
66           'application to re-authorize')
67
68if __name__ == '__main__':
69  main(sys.argv)
70