Pages

2010-09-20

Google Tasks API case study

This post is an update of http://privacylog.blogspot.com/2010/07/api-for-google-tasks.html

Update 2011-05-12 the official API is now at http://code.google.com/apis/tasks/index.html thanks to Josh for the ping.

There is no official API for Google Tasks at this time. But, below is full read-only access to all your tasks across all your lists. I am including a simple app that sends this to you via email (This mail WILL go to your spam folder). I have this running at home to automatically print out a copy of all task lists periodically.
#!/bin/bash

cd /tmp
rm -f message; touch message

curl https://www.google.com/accounts/ClientLogin \
-d Email=YOURUSENAME@gmail.com \
-d Passwd=YOURPASSWORD \
-d source=privacylog \
-d service=goanna_mobile > token

AUTH=$(sed -n '/Au/s/A/a/p' token)
HEADER="Authorization: GoogleLogin $AUTH"
URL="https://mail.google.com/tasks/m"
curl --header "$HEADER" "$URL" > main

for list in $(grep -o '"[0-9:]\{20,25\}:0"' main | tr -d '"' | sort -u)
do 
curl --header "$HEADER" "$URL?listid=$list" > list
echo >> message
title=$(sed -n 's|.*selected="selected">\([^<]\+\).*|\1|gp' list | head -n1)
echo "### $title ###" >> message
sed -n 's|\([^<]\{1,\}\).*|[ ]  \1|p' list >> message
# This one below indents sub tasks but only works on Linux
# sed -n -e 's/.* .*//p' -e 's|\([^<]\+\).*|\1|p' list | sed -n -e '/./!{N;s/\n/  /}' -e '/./p' | sed 's/^/[ ]  /' >> message
done

mail -s "Weekly review" YOURUSERNAME@gmail.com < message

rm token main list message
Notes for Mac: use * instead of \+,