blob: 9af1a48b2930b172e9c9063ae34815f536d23a78 [file] [log] [blame]
Joe Gregoriob071ca72012-03-29 17:01:32 -04001#!/usr/bin/python
2#
3# Copyright 2012 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 illustrates how to retrieve the information of a creative.
18
19Tags: creatives.insert
20"""
21
Joe Gregorio731680a2013-03-18 09:15:57 -040022__author__ = ('david.t@google.com (David Torres)',
23 'jdilallo@google.com (Joseph DiLallo)')
Joe Gregoriob071ca72012-03-29 17:01:32 -040024
Joe Gregorio562c9ba2013-04-05 14:24:30 -040025import argparse
Joe Gregoriob071ca72012-03-29 17:01:32 -040026import pprint
27import sys
Joe Gregoriob071ca72012-03-29 17:01:32 -040028
John Asmuth864311d2014-04-24 15:46:08 -040029from googleapiclient import sample_tools
Joe Gregorio562c9ba2013-04-05 14:24:30 -040030from oauth2client import client
31
32# Declare command-line flags.
33argparser = argparse.ArgumentParser(add_help=False)
34argparser.add_argument('account_id', type=int,
35 help='The ID of the account that contains the creative')
36argparser.add_argument('buyer_creative_id',
37 help='A buyer-specific id that identifies this creative')
Joe Gregoriob071ca72012-03-29 17:01:32 -040038
39
40def main(argv):
Joe Gregoriob071ca72012-03-29 17:01:32 -040041 # Authenticate and construct service.
Joe Gregorio562c9ba2013-04-05 14:24:30 -040042 service, flags = sample_tools.init(
Joe Gregorio959d2412013-09-05 12:53:31 -040043 argv, 'adexchangebuyer', 'v1.3', __doc__, __file__, parents=[argparser],
Joe Gregorio562c9ba2013-04-05 14:24:30 -040044 scope='https://www.googleapis.com/auth/adexchange.buyer')
45
46 account_id = flags.account_id
47 buyer_creative_id = flags.buyer_creative_id
Joe Gregoriob071ca72012-03-29 17:01:32 -040048
49 try:
50 # Construct the request.
51 request = service.creatives().get(accountId=account_id,
Joe Gregoriob071ca72012-03-29 17:01:32 -040052 buyerCreativeId=buyer_creative_id)
53
54 # Execute request and print response.
Joe Gregorio562c9ba2013-04-05 14:24:30 -040055 pprint.pprint(request.execute())
56 except client.AccessTokenRefreshError:
Joe Gregoriob071ca72012-03-29 17:01:32 -040057 print ('The credentials have been revoked or expired, please re-run the '
58 'application to re-authorize')
59
60if __name__ == '__main__':
61 main(sys.argv)