Friday, March 23, 2007

New Blogger Interface

Previously, wrote notes on the Blogger Interface. Was it ATOM? (Probably)

These are not meant to be instructions! They are notes on the process of using the API manually

New API doco:

"To get a feed of a blog's entries, you send the following HTTP request to Blogger" [Everything in XML!]
curl -o blog.1

"After you send the GET request, Blogger may return a redirect, depending on various factors. If so, send another GET request to the redirect URL." Curl takes care of this...

Posting: Client Login [URL encoding needs to be done in the POSTS]

Then authenticate the user. To do that, send a POST request to the following URL:


POST /accounts/ClientLogin HTTP/1.0
Content-type: application/x-www-form-urlencoded

[CAPTCHA example]
POST /accounts/ClientLogin HTTP/1.0
Content-type: application/x-www-form-urlencoded


logintoken(optional) Token representing the specific CAPTCHA challenge. Google supplies this token and the CAPTCHA image URL in a login failed response with the error code "CaptchaRequired".
logincaptcha(optional) String entered by the user as an answer to a CAPTCHA challenge.

curl's POST doesn't work... This URL has a working example for calendar using wget...

$ wget --no-check-certificate -O blog.2 --post-data ''
$ grep Auth blog.2

To use the 'Auth' string:
wget -q -O- --header='Authorization: GoogleLogin auth=XXX' http://...

And this piece from the instructions is cracker-jack! You gotta go look at the
Now send the POST request to the appropriate Blogger URL:
Note: This URL is the same as the URL in the <link rel=""> tag that appears in the <head> section of the human-readable version of the blog.

It also appears in the XML downloaded:

And this is how you push it in :-)
In the body of the new POST request, place the Atom element you created above, using the application/atom+xml content type.

Final command:
a=$(grep Auth blog.2)
wget -q -O- --header="Authorization: GoogleLogin $a" --header 'content-type: application/atom+xml' --post-file=blog-entry.xml

List all Blogs owned by user

Save XML description of all users blogs & tags into file 'blog.4'
wget -q -Oblog.4 --header="Authorization: GoogleLogin $a"

neat. Something worked as advertised...

Query a Blog

Save XML of all blog entries made in March, 2007 (in blog.5)
wget -O blog.5 ''

Cute quote from doco (I wonder where to find *that* list?):
To query using other standard GData query parameters, just change the URL to use other parameters. (Note that Blogger doesn't support GData category queries or full-text search queries.)

Which might be here:

Deletes and Update/Edits

Too hard... Not clear. no examples of fully generated URI's. Tried to generate a URI for an item/article - failed.

here's the suggestions. untested...

Note the edit URI's of the events you'd like to delete:
wget ... | tidy -xml -wrap 999 | grep edit

Delete the event by using its edit URI; this is a two step process, because wget does not redirect correctly:

wget -nv -O- --header='Authorization: GoogleLogin auth=XXX' --header='X-HTTP-Method-Override: DELETE' --post-data='' 'URI'

Watch the output and note the redirect URI with gsessionid attached, then execute:

wget -nv -O- --header='Authorization: GoogleLogin auth=XXX' --header='X-HTTP-Method-Override: DELETE' --post-data='' 'URI?gsessionid=YYY'

No comments: