More Curling with Google Blogger (new)
In case you have been playing around with the CURL hints given on Google’s Blogger Data API Developer’s Guide and had problems, please peruse the following.
curl --silent --header “Content-Type: application/x-www-form-urlencoded” -X POST --data-binary @file.txt https://www.google.com/accounts/ClientLogin > auth.txt
The above command needs only your email and password (from
file.txt) in the following format:
Please substitute your email and password above. Notice that I have dumped the auth token in a file (I don’t know anything about cookies). We are interested only in the line that says “Auth=”. We need to format that in the header as “auth=” when we send a POST or DELETE request.
POSTING TO BLOGGER
We first need to get our POST URI correct.
This will look like
Here is all you need to post a file named sample.html:
curl --silent --compressed --location --location-trusted --header “Authorization: GoogleLogin auth=$AUTH” --header “Content-Type:application/atom+xml;charset=UTF-8” --header $ENCHDR -i -X POST --data-binary @sample.html $URI > posted.xml
The variable ENCHDR is not required but was being sent by the Java Client. It is
export ENCHDR=”Accept-Encoding:gzip”. I write the return value into posted.xml, we should check for a “201 Created” in it to ensure that the write was a success, as follows:
grep -q “HTTP/1.1 201” posted.xml.
The return file may be used for editing and updating the post. The edit link is what is required for updating and deleting.
DELETING A POST
Deleting a post requires the Edit-Link which contains the BLOGID (a large number) and the POSTID (an even larger one). The format is like this:
http://www.blogger.com/feeds/98888814/posts/default/3456482919486403855. This may be taken from the file returned by the POST procedure. Also the source of the page will contain it. The command is simply this.
curl --silent --compressed --location --location-trusted --header “Authorization: GoogleLogin auth=$AUTH” -X DELETE $URI
This requires no authorization.
curl --silent --location --location-trusted -X GET $URI > myfeeds.xml
Here is the template for the post:
MYCONTENT – blah blah
This program uses the popular curl program for connecting. It was tested on a MAC OSX Tiger with:
$ curl -V
curl 7.13.1 (powerpc-apple-darwin8.0) libcurl/7.13.1 OpenSSL/0.9.7l zlib/1.2.3
The view program parses out titles and Edit-URI’s using a single line of
My vim mapping for this are as follows:
map ;bbt :0<CR>:r !blogger.sh -t<CR>:set filetype=html<CR>:g/^$/d<CR>/EDIT_THIS<CR>cw
” ” (P)ew- posts new entry
map ;bbp :!blogger.sh -p %<CR>
” ” (V)iew list and delete selected
map ;bbv :!blogger.sh -v<CR>
” ” (H)elp
map ;bbh :!blogger.sh -h<CR>
Once you have extracted the template, you may save and modify it, and then modify the bbt setting as follows:
map ;bbt :0r ~/.bb.html<CR>:set filetype=html<CR>A
I am setting the filetype since I use the unparalleled HTML.vim for formatting.
Happy posting! Long live Vim and the command-line!
[Edited in Vim using HTML.vim]