New version at https://privacylog.blogspot.com/2010/09/updated-google-tasks-api.html
Here is the API for Google Tasks. It only supports your default list and it’s read-only. And for free, it emails your task list to you. (This mail WILL go to your spam folder)
```sh #!/bin/bash cd $HOME curl
curl https://www.google.com/accounts/ClientLogin
-d Email=YOURUSERNAME@gmail.com
-d Passwd=YOURPASS
-d source=privacylog
-d service=goanna_mobile > token
AUTH=$(sed -n ‘s/Auth=/auth=/p’ token) HEADER=”Authorization: GoogleLogin $AUTH” URL=”https://mail.google.com/tasks/ig” curl –header “$HEADER” “$URL” > tasks
grep -o “"(name|task_date|notes)":"[^"]*"” tasks > list
mail -s “Your tasks” YOURUSERNAME@gmail.com > list
rm token tasks list
If you want to have that to run daily at 7am, save that script to ~/googletasks.sh and run:
```sh chmod 700 ~/googletasks.sh crontab -l > ~/tmpcron echo “0 7 * * * $HOME/googletasks.sh” » ~/tmpcron crontab ~/tmpcron rm ~/tmpcron
Update 2010-08-12: Made code a litte more readable, thanks to a note from Sandstrp, see comments.
▧
Comments
Do you I website where I can paste source code and it spits out color coded source code. Then I can view source and use that HTML in Blogger?
William Entriken
Hi, could you help me with what "/Au" does in sed?
Unknown
Original line of code: AUTH=$(sed -n '/Au/s/A/a/p' token)
William Entriken
Sure, since sed is in -n (non-print mode), this matches lines with /Au/ and then /p (prints) them, as opposed to printing every line with an A in it.
Of course a more straightforward approach is just s/Auth/auth/p which does the same thing. I'll put that in the post.
Is there any way to access https://mail.google.com/tasks/ig using oAuth or any other method that does not require asking the user to provide their password?
Dmitry Panov
Nope, we're all waiting for that. This post of course is just a workaround. Feel free to vote on that feature at https://code.google.com/p/gdata-issues/issues/detail?id=987
William Entriken
Link is now: https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=985
Anonymous
Hi.
Anonymous
I have implemented this code in Java and when I run it no Android simulator I get:
P3P: CP="This is not a P3P policy! See https://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657
Can you advise please?
Hi Anonymous. Is this Java code available for inspection?
William Entriken
URI uri = new URI("https://www.google.com/accounts/ClientLogin?Email=user@gmail.com&Passwd=pass&source=privacylog&service=goanna_mobile");
Anonymous
HttpPost post = new HttpPost(uri);
HttpClient client = new DefaultHttpClient();
HttpResponse response1 = client.execute(post);
InputStreamReader isr = new InputStreamReader(response1.getEntity().getContent(),"UTF-8");
char buff[] = new char[ (int) response1.getEntity().getContentLength()];
int n;
StringBuffer sb = new StringBuffer();
while ((n = isr.read(buff, 0, (int)response1.getEntity().getContentLength() - 1)) > 0) {
sb.append(buff, 0, n);
}
String a = sb.toString();
String arr[] = a.split("
");
String auth[] = arr[2].split("=");
isr.close();
URI uri1 = new URI("https://mail.google.com/tasks/ig");
HttpGet post1 = new HttpGet(uri1);
post1.addHeader("Authorization","GoogleLogin auth=" + auth[1].trim());
HttpResponse response = client.execute(post1);
isr = new InputStreamReader(response.getEntity().getContent(),"UTF-8");
buff = new char[ (int) response.getEntity().getContentLength()];
sb = new StringBuffer();
while ((n = isr.read(buff, 0, (int)response.getEntity().getContentLength() - 1)) > 0) {
sb.append(buff, 0, n);
}
a = sb.toString(); //as String is easy ... but with
isr.close();
In response header i get the above message.
I believe this is an implementation-specific problem. See https://groovy.329449.n5.nabble.com/Httpbuider-issues-td396109.html
William Entriken
I couldn't find an Android Simulator out there, but low level problems like this might be investigated with ethereal.
It doen't affect you, but there's a new version of this post at https://privacylog.blogspot.com/2010/09/updated-google-tasks-api.html
Please discuss this topic anywhere and let me know any great comments or media coverage I should link here.