Sunday, August 27

Authenticating to Google Accounts from the Command Line

The beta version of Blogger uses GData for its API and Google Accounts for logins, which means that it requires the GoogleLogin authorization scheme on API requests. This is more secure, but slightly tougher to work with than HTTP Basic authorization.

Sure, there are libraries (Java and C#) for handling this, but where’s the fun in that? Here’s how to do the API using just curl and sed, in a delightful one-liner:

curl -H "`curl -s -d Email=e-mail address -d Passwd=password -d source=your app name -d service=blogger https://www.google.com/accounts/ClientLogin | sed -n -e \"s/Auth=\(.*\)/Authorization: GoogleLogin auth=\1/p\"`" http://beta.blogger.com/feeds/blog id/posts/full

Note that for the e-mail address, you’ll need to replace “@” with “%40” as per URL encoding.