The Accidental Rubyist

invalid byte sequence in UTF-8

More Curling with Google Blogger (new)

leave a comment »

This is a followup on my previous post on Curling with Google Blogger Data API.

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 > 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.


We first need to get our POST URI correct.
export URI=”$BLOGNAME/feeds/posts/default”
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 requires the Edit-Link which contains the BLOGID (a large number) and the POSTID (an even larger one). The format is like this: 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.

export URI=$BLOGNAME/feeds/posts/default
curl --silent --location --location-trusted -X GET $URI > myfeeds.xml

Here is the template for the post:

<?xml version=”1.0″?>
<entry xmlns=””&#62;
<title type=”text”>MYTITLE</title>
<content type=”xhtml”>
MYCONTENT – blah blah

For a complete listing of the program please download from here (6kb).

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 ruby.

My vim mapping for this are as follows:

map ;bbt :0<CR>:r ! -t<CR>:set filetype=html<CR>:g/^$/d<CR>/EDIT_THIS<CR>cw
” ” (P)ew- posts new entry
map ;bbp :! -p %<CR>
” ” (V)iew list and delete selected
map ;bbv :! -v<CR>
” ” (H)elp
map ;bbh :! -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.

See also:

  1. Vim Blogger Plugin

  2. Emacs Client

  3. Google API

  4. Also check the wonderful for Movable Type.

Happy posting! Long live Vim and the command-line!

[Edited in Vim using HTML.vim]


Written by totalrecall

March 6, 2007 at 4:17 am

Posted in being_geeky, unix

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: