Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 1 | #!/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 | |
| 19 | Tags: creatives.insert |
| 20 | """ |
| 21 | |
Joe Gregorio | 731680a | 2013-03-18 09:15:57 -0400 | [diff] [blame] | 22 | __author__ = ('david.t@google.com (David Torres)', |
| 23 | 'jdilallo@google.com (Joseph DiLallo)') |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 24 | |
Joe Gregorio | 562c9ba | 2013-04-05 14:24:30 -0400 | [diff] [blame^] | 25 | import argparse |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 26 | import pprint |
| 27 | import sys |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 28 | |
Joe Gregorio | 562c9ba | 2013-04-05 14:24:30 -0400 | [diff] [blame^] | 29 | from apiclient import sample_tools |
| 30 | from oauth2client import client |
| 31 | |
| 32 | # Declare command-line flags. |
| 33 | argparser = argparse.ArgumentParser(add_help=False) |
| 34 | argparser.add_argument('account_id', type=int, |
| 35 | help='The ID of the account to which submit the creative') |
| 36 | argparser.add_argument('buyer_creative_id', |
| 37 | help='A buyer-specific id identifying the creative in' |
| 38 | 'this ad') |
| 39 | argparser.add_argument('agency_id', type=int, |
| 40 | help='The ID of the agency who created this ad') |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 41 | |
| 42 | |
| 43 | def main(argv): |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 44 | # Authenticate and construct service. |
Joe Gregorio | 562c9ba | 2013-04-05 14:24:30 -0400 | [diff] [blame^] | 45 | service, flags = sample_tools.init( |
| 46 | argv, 'adexchangebuyer', 'v1.2', __doc__, __file__, parents=[argparser], |
| 47 | scope='https://www.googleapis.com/auth/adexchange.buyer') |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 48 | |
Joe Gregorio | 562c9ba | 2013-04-05 14:24:30 -0400 | [diff] [blame^] | 49 | account_id = flags.account_id |
| 50 | agency_id = flags.agency_id |
| 51 | buyer_creative_id = flags.buyer_creative_id |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 52 | try: |
| 53 | # Create a new creative to submit. |
| 54 | creative_body = { |
| 55 | 'accountId': account_id, |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 56 | 'buyerCreativeId': buyer_creative_id, |
| 57 | 'HTMLSnippet': ('<html><body><a href="http://www.google.com">' |
| 58 | 'Hi there!</a></body></html>'), |
| 59 | 'clickThroughUrl': ['http://www.google.com'], |
| 60 | 'width': 300, |
| 61 | 'height': 250, |
| 62 | 'advertiserName': 'google' |
| 63 | } |
Joe Gregorio | 731680a | 2013-03-18 09:15:57 -0400 | [diff] [blame] | 64 | if agency_id: |
| 65 | creative_body['agencyId'] = agency_id |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 66 | creative = service.creatives().insert(body=creative_body).execute() |
| 67 | # Print the response. If the creative has been already reviewed, its status |
| 68 | # and categories will be included in the response. |
Joe Gregorio | 562c9ba | 2013-04-05 14:24:30 -0400 | [diff] [blame^] | 69 | pprint.pprint(creative) |
| 70 | except client.AccessTokenRefreshError: |
Joe Gregorio | b071ca7 | 2012-03-29 17:01:32 -0400 | [diff] [blame] | 71 | print ('The credentials have been revoked or expired, please re-run the ' |
| 72 | 'application to re-authorize') |
| 73 | |
| 74 | if __name__ == '__main__': |
| 75 | main(sys.argv) |