Search This Blog

Sunday, July 21, 2013

Post on Blogspot using cURL with bash

The following bash-script posts an article in the blogspot.


# Authenticate
# Requires $GDATA_PASSWORD to be set as an environment variable.
G_AUTH_TOKEN=`curl 2>/dev/null \
    -d \
    -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" \
    "" --data "@blog_post.xml"

The followings are the field specific for a user account and a blog. user account for a blog
$GDATA_PASSWORD: user password
YOUR_BLOGS_ID: blog id
blog_post.xml: data for upload

The following is an xml example to upload.

<entry xmlns="">  
  <title type="text">Knock knock</title>  
  <content type="xhtml">  
    <div xmlns="">  
      <p>Who's there?</p>  
      <p>Orange who?</p>  
      <p>Orange you glad you know how to post using curl?!? (lol!)</p>  
  <category scheme="" term="joke"/>  
  <category scheme="" term="curl"/>  

In this xml, category scheme defines labels.

Code formatter:

No comments:

Post a Comment

Blog Archive