{% extends "base.html" %} {% block scripts %} {% endblock %} {% block steptitle %} Step 5: Cut and paste this code and run it {% endblock %} {% block stepbody %}
You can also visit the Python Client Documentation for this API.
"""Simple command-line example. """ import gflags import httplib2 import logging import sys from apiclient.discovery import build from oauth2client.file import Storage from oauth2client.client import OAuth2WebServerFlow from oauth2client.tools import run FLAGS = gflags.FLAGS FLOW = OAuth2WebServerFlow( client_id='{{ client_id }}', client_secret='{{ client_secret }}', scope='https://www.googleapis.com/auth/{{ service_name }}', user_agent='{{ service_name }}-{{ platform }}-boilerplate-sample/1.0') gflags.DEFINE_enum('logging_level', 'ERROR', ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'], 'Set the level of logging detail.') def main(argv): try: argv = FLAGS(argv) except gflags.FlagsError, e: print '%s\\nUsage: %s ARGS\\n%s' % (e, argv[0], FLAGS) sys.exit(1) logging.getLogger().setLevel(getattr(logging, FLAGS.logging_level)) storage = Storage('{{ service_name }}.dat') credentials = storage.get() if credentials is None or credentials.invalid == True: credentials = run(FLOW, storage) http = httplib2.Http() http = credentials.authorize(http) # Build the service service = build("{{ service_name }}", "{{ service_version }}", http=http, developerKey="{{ developerKey }}") # New code goes here: # ... # service.<collection name>().<method name>().exectute() if __name__ == '__main__': main(sys.argv)
Use the API Explorer below to select API methods to use and see how the calls should appear in Python:
{% endblock %}