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:
http://code.google.com/apis/blogger/gdata.html#Get_Feed_Manual


"To get a feed of a blog's entries, you send the following HTTP request to Blogger" [Everything in XML!]
curl -o blog.1 http://itilopia.blogspot.com/feeds/posts/default


"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:
https://www.google.com/accounts/ClientLogin



From http://code.google.com/apis/accounts/AuthForInstalledApps.html

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

Email=johndoe@gmail.com&Passwd=north23AZ&service=blogger&source=Gulp-CalGulp-1.05



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

accountType=HOSTED_OR_GOOGLE&Email=johndoe@gmail.com&Passwd=north23AZ&service=blogger&
source=Gulp-CalGulp-1.05&logintoken=DQAAAGgA...dkI1LK9&logincaptcha=brinmar


Where
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...
http://denizyuret.blogspot.com/2006/05/google-calendar-how-to-delete-multiple.html



$ wget --no-check-certificate -O blog.2 --post-data 'Email=stevej098@gmail.com&Passwd=xxxxxxx&service=blogger&source=Gulp-CalGulp-1.05' https://www.google.com/accounts/ClientLogin
$ 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:
http://www.blogger.com/feeds/blogID/posts/default
Note: This URL is the same as the URL in the <link rel="service.post"> tag that appears in the <head> section of the human-readable version of the blog.


It also appears in the XML downloaded:
<code><entry><id>tag:blogger.com,1999:blog-3110200838296430371.post-4190105953841900395</id>

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 http://www.blogger.com/feeds/3110200838296430371/posts/default



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" http://www.blogger.com/feeds/default/blogs

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 'http://itilopia.blogspot.com/feeds/posts/default?updated-min=2007-03-01T00:00:00&updated-max=2007-03-31T23:59:59'

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:
http://www.google.com/base/api/demo/html/demo.html#query


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: