Skip to content

Instantly share code, notes, and snippets.

@qmacro
Created May 15, 2011 13:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qmacro/973175 to your computer and use it in GitHub Desktop.
Save qmacro/973175 to your computer and use it in GitHub Desktop.
Sample Task insert using Google API Client library for Python
# Insert a new task into the user's default task list
# Based upon the sample urlshortener.py code for the
# Google API Python Client library
# http://code.google.com/p/google-api-python-client/source/browse/samples/urlshortener/urlshortener.py
# Note that the response to the task insert is a 200, rather than a 201
# If you want to run this, get your own client_id and client_secret using the
# Google API Console https://code.google.com/apis/console/
import gflags
import httplib2
import logging
import pprint
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='sekrit!',
client_secret='sekrit as well!',
scope='https://www.googleapis.com/auth/tasks',
user_agent='task-cmdline-test/1.0')
gflags.DEFINE_enum('logging_level', 'ERROR',
['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
'Set the level of logging detail.')
storage = Storage('auth.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run(FLOW, storage)
httplib2.debuglevel = 1
http = httplib2.Http()
http = credentials.authorize(http)
service = build("tasks", "v1", http=http)
taskdata = { 'title': 'Test task insert' }
result = service.tasks().insert(tasklist='@default', body=taskdata).execute()
print result['id']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment