Post on Blogger using curl


This command line curl script reads an XML file containing the blog post's XML and uses curl to authenticate and post to Blogger. Here is the XML for an example post:
<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Knock knock</title>
  <content type="xhtml">
    <div xmlns="http://www.w3.org/1999/xhtml">
      <p>Who's there?</p>
      <p>Orange.</p>
      <p>Orange who?</p>
      <p>Orange you glad you know how to post using curl?!? (lol!)</p>
    </div>
  </content>
  <category scheme="http://www.blogger.com/atom/ns#" term="joke"/>
  <category scheme="http://www.blogger.com/atom/ns#" term="curl"/>
</entry>
With the above stored in blog_post.xml, we can now post it using the following shell script:
#!/bin/sh

# Authenticate
# Requires $GDATA_PASSWORD to be set as an environment variable.
G_AUTH_TOKEN=`curl 2>/dev/null https://www.google.com/accounts/ClientLogin \
    -d Email=YOUR_EMAIL_ADDRESS@example.com \
    -d Passwd=$GDATA_PASSWORD  \
    -d accountType=GOOGLE \
    -d source=curlExample \
    -d service=blogger \
  | grep '^Auth=' | cut -c 6-`

# Post on my blog.
curl -v --request POST -H "Content-Type: application/atom+xml" \
    -H "Authorization: GoogleLogin auth=$G_AUTH_TOKEN" \
    "http://www.blogger.com/feeds/YOUR_BLOGS_ID/posts/default" --data "@blog_post.xml"

4 comments:

weakish said...

Seems the end quote is missing.

It should be --data "@post.xml".

Fredy said...

Cool!!!
That's what I was looking for.

Linuxbyexamples said...

How can I use this method to make a post-draft instead of puslished-post ? I mean when running this script it make post publish immediately, but I want to make it draft first.

Another question, How can I include meta tag description (Search Description) in this .xml file ?

العمدة said...

thanks, it works
can it work with php Curl?
what changes are needed?