Update adexchangebuyer samples to use apiclient.sample_tools.
Reviewed in https://codereview.appspot.com/8410044/.
diff --git a/samples/adexchangebuyer/submit_creative.py b/samples/adexchangebuyer/submit_creative.py
index abba2e3..e7ba2d7 100644
--- a/samples/adexchangebuyer/submit_creative.py
+++ b/samples/adexchangebuyer/submit_creative.py
@@ -22,36 +22,33 @@
__author__ = ('david.t@google.com (David Torres)',
'jdilallo@google.com (Joseph DiLallo)')
+import argparse
import pprint
import sys
-import gflags
-from oauth2client.client import AccessTokenRefreshError
-import sample_utils
-# Declare command-line flags, and set them as required.
-gflags.DEFINE_string('account_id', None,
- 'The ID of the account to which submit the creative',
- short_name='a')
-gflags.MarkFlagAsRequired('account_id')
-gflags.DEFINE_string('buyer_creative_id', None,
- 'A buyer-specific id identifying the creative in this ad',
- short_name='c')
-gflags.MarkFlagAsRequired('buyer_creative_id')
-gflags.DEFINE_string('agency_id', None,
- 'The id of the agency who created this ad',
- short_name='g')
+from apiclient import sample_tools
+from oauth2client import client
+
+# Declare command-line flags.
+argparser = argparse.ArgumentParser(add_help=False)
+argparser.add_argument('account_id', type=int,
+ help='The ID of the account to which submit the creative')
+argparser.add_argument('buyer_creative_id',
+ help='A buyer-specific id identifying the creative in'
+ 'this ad')
+argparser.add_argument('agency_id', type=int,
+ help='The ID of the agency who created this ad')
def main(argv):
- sample_utils.process_flags(argv)
- account_id = gflags.FLAGS.account_id
- buyer_creative_id = gflags.FLAGS.buyer_creative_id
- agency_id = gflags.FLAGS.agency_id
- pretty_printer = pprint.PrettyPrinter()
-
# Authenticate and construct service.
- service = sample_utils.initialize_service()
+ service, flags = sample_tools.init(
+ argv, 'adexchangebuyer', 'v1.2', __doc__, __file__, parents=[argparser],
+ scope='https://www.googleapis.com/auth/adexchange.buyer')
+ account_id = flags.account_id
+ agency_id = flags.agency_id
+ buyer_creative_id = flags.buyer_creative_id
try:
# Create a new creative to submit.
creative_body = {
@@ -69,8 +66,8 @@
creative = service.creatives().insert(body=creative_body).execute()
# Print the response. If the creative has been already reviewed, its status
# and categories will be included in the response.
- pretty_printer.pprint(creative)
- except AccessTokenRefreshError:
+ pprint.pprint(creative)
+ except client.AccessTokenRefreshError:
print ('The credentials have been revoked or expired, please re-run the '
'application to re-authorize')