I was becoming slightly upset with Blogger.com, since it does some insane things like puts BR tags in the middle of PRE elements, which meant the syntax highlighting script I wanted to use was going nuts. I also gradually realised that none of the blogging clients work with the "new Blogger.com" although for me (who has only been blogging a few months) it has been the "only Blogger.com".
So, with a quick search around for documentation from code.google.com, I was able to discover that Blogger.com uses the google GData API with a bit of Atom mixed in. I have no real ideas about these specifications, but http://code.google.com/apis/blogger/gdata.html explains it. Note that another document I found: http://code.blogspot.com/archives/atom-docs.html seems depracated, but I can't confirm that at all.
Python is my language of choice for these things, so I started hacking.
Step 1: Authenticate with Google Login stuff. This is explained in http://code.google.com/apis/accounts/AuthForInstalledApps.html but basically you need to:
- Send a post request to
- Set the service value of the data to "blogger" (this had me for a while)
Parse the body of the response for an "Auth" token
Include the header
Authorization: GoogleLogin auth=yourAuthValue
in all your requests from thereon in (not obvious from the authentication docs)
<link rel="service.post" type="application/atom+xml" ...but you can also fetch it from the blog's feed from the blog's name (see the API documentation).
Once you have this ID, posting is a matter of using the ID with your auth token, and entering data in an XML format as the post's body. Not forgetting to set the correct content-type for your post to "application/atom+xml". If you have posted correctly, the server returns a 201 Created response.
I have spared you the boring details of making urllib/urllib2 work with these things, but I have written some sample code and a command line client which you can browse online here: http://pygbloggerlib.googlecode.com/svn/trunk/gblogger/client.py as well as accessing the googlecode page (no releases yet) here: http://code.google.com/p/pygbloggerlib/
You can actually see this post online (if I haven't deleted the test blog) here: http://my-test-atom-blog.blogspot.com/2007/03/this-is-test-post.html
>>> from gblogger.client import BlogClient
>>> import getpass
>>> passwd = getpass.getpass()
>>> c = BlogClient('my-test-atom-blog', 'email@example.com', passwd)
>>> c.post('this is a test post', 'this is the body of the test post with some html')
HTTP Error 201: Created
Since I never have any spare time, my plans for this library are a bit shaky. It is a toy library in that there are no real tests, and failure conditions are not really dealt with properly. Ideally I will:
- Write a PIDA plugin for blogging
- Merge it into something like BloGTK, or write a miniature gui client of my own.
I have no idea how to publicize this to the Blogger.com community, but if any of you big Blogger admins or google developers are interested in spreading the word, (or silencing the word!) please let me know.
(some more useful links)
Well, editing now works in the library! I know this because I accidentally overwrote this post! Lucky for the unnoficial planet python it was still lying around there!