XMLRPC: blogger.newPost- Creating a new Post

blogger.newPost is used to create a new post. Unlike wordpress newPost, where you can specify the title of the post, blogger,newPost can be used to post the content

It takes the following parameters

  1. appkey: ignored (pass some blank value)
  2. blogid: the blog where the post is to be added,
  3. username,
  4. password,
  5. content: the contents of the post
  6. to publish or not

The PHP program will look something like this


/*The URL of the blog*/
$BLOGURL = "http://localhost/wordpress";

function get_response($URL, $context) {
    if(!function_exists('curl_init')) {
    die ("Curl PHP package not installedn");

    /*Initializing CURL*/
    $curlHandle = curl_init();

    /*The URL to be downloaded is set*/
    curl_setopt($curlHandle, CURLOPT_URL, $URL);
    curl_setopt($curlHandle, CURLOPT_HEADER, false);
    curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
    curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);

    /*Now execute the CURL, download the URL specified*/
    $response = curl_exec($curlHandle);
    return $response;

/*Creating the blogger.newPost request which takes on six parameters
 appkey: ignored (pass some blank value)
 blogid: the blog where the post is to be added,
 to publish or not*/
function blogger_newPost($appkey,$blogid, $username, $password, $content, $toPublish) {
   global $BLOGURL;
   $request = xmlrpc_encode_request("blogger.newPost",
      array($appkey, $blogid,$username, $password, $content ,$toPublish));

    /*Making the request to wordpress XMLRPC of your blog*/
    $xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
    $response = xmlrpc_decode($xmlresponse);

    /*Printing the response on to the console*/


$USERNAME = "admin";
$PASSWORD = "check";
/*The id of the blog*/
$blogid = 1;

/*the contents of the post*/
$description = "This is the contents of the new post.";

/*Whether the post has to be published, usually ignored*/
$toPublish = false;

blogger_newPost($appkey, $blogid, $USERNAME, $PASSWORD, $description, $toPublish);
echo "n";

On successful execution

$ php blogger.newPost.php
<?xml version="1.0"?>


where the return value is the ID of the new Post


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s