blob: abba2e371ff51a9a033677c468184fbbbc4ab4b4 [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 submit a new creative for its verification.
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
25import pprint
26import sys
27import gflags
28from oauth2client.client import AccessTokenRefreshError
29import sample_utils
30
31# Declare command-line flags, and set them as required.
32gflags.DEFINE_string('account_id', None,
33 'The ID of the account to which submit the creative',
34 short_name='a')
35gflags.MarkFlagAsRequired('account_id')
Joe Gregoriob071ca72012-03-29 17:01:32 -040036gflags.DEFINE_string('buyer_creative_id', None,
37 'A buyer-specific id identifying the creative in this ad',
38 short_name='c')
39gflags.MarkFlagAsRequired('buyer_creative_id')
Joe Gregorio731680a2013-03-18 09:15:57 -040040gflags.DEFINE_string('agency_id', None,
41 'The id of the agency who created this ad',
42 short_name='g')
Joe Gregoriob071ca72012-03-29 17:01:32 -040043
44
45def main(argv):
46 sample_utils.process_flags(argv)
47 account_id = gflags.FLAGS.account_id
Joe Gregoriob071ca72012-03-29 17:01:32 -040048 buyer_creative_id = gflags.FLAGS.buyer_creative_id
Joe Gregorio731680a2013-03-18 09:15:57 -040049 agency_id = gflags.FLAGS.agency_id
Joe Gregoriob071ca72012-03-29 17:01:32 -040050 pretty_printer = pprint.PrettyPrinter()
51
52 # Authenticate and construct service.
53 service = sample_utils.initialize_service()
54
55 try:
56 # Create a new creative to submit.
57 creative_body = {
58 'accountId': account_id,
Joe Gregoriob071ca72012-03-29 17:01:32 -040059 'buyerCreativeId': buyer_creative_id,
60 'HTMLSnippet': ('<html><body><a href="http://www.google.com">'
61 'Hi there!</a></body></html>'),
62 'clickThroughUrl': ['http://www.google.com'],
63 'width': 300,
64 'height': 250,
65 'advertiserName': 'google'
66 }
Joe Gregorio731680a2013-03-18 09:15:57 -040067 if agency_id:
68 creative_body['agencyId'] = agency_id
Joe Gregoriob071ca72012-03-29 17:01:32 -040069 creative = service.creatives().insert(body=creative_body).execute()
70 # Print the response. If the creative has been already reviewed, its status
71 # and categories will be included in the response.
72 pretty_printer.pprint(creative)
73 except AccessTokenRefreshError:
74 print ('The credentials have been revoked or expired, please re-run the '
75 'application to re-authorize')
76
77if __name__ == '__main__':
78 main(sys.argv)