Created
May 15, 2011 13:54
-
-
Save qmacro/973175 to your computer and use it in GitHub Desktop.
Sample Task insert using Google API Client library for Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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