• 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"""Gets all preferred deals for the logged in user's account.
18
19Tags: preferreddeals.list
20"""
21from __future__ import print_function
22
23__author__ = 'sgomes@google.com (Sérgio Gomes)'
24
25import argparse
26import sys
27
28from googleapiclient import sample_tools
29from oauth2client import client
30
31
32def main(argv):
33  # Authenticate and construct service.
34  service, flags = sample_tools.init(
35      argv, 'adexchangeseller', 'v1.1', __doc__, __file__, parents=[],
36      scope='https://www.googleapis.com/auth/adexchange.seller.readonly')
37
38  try:
39    # Retrieve preferred deals list in pages and display data as we receive it.
40    request = service.preferreddeals().list()
41
42    if request is not None:
43      result = request.execute()
44      if 'items' in result:
45        deals = result['items']
46        for deal in deals:
47          output = 'Deal id "%s" ' % deal['id']
48
49          if 'advertiserName' in deal:
50            output += 'for advertiser "%s" ' % deal['advertiserName']
51
52          if 'buyerNetworkName' in deal:
53            output += 'on network "%s" ' % deal['buyerNetworkName']
54
55          output += 'was found.'
56          print(output)
57      else:
58        print('No preferred deals found!')
59  except client.AccessTokenRefreshError:
60    print ('The credentials have been revoked or expired, please re-run the '
61           'application to re-authorize')
62
63if __name__ == '__main__':
64  main(sys.argv)
65