XMLRPC: blogger.getRecentPosts

blogger.getRecentPosts can be used to get the recent posts. All you need is to specify the count. It is part of the Blogger API and can be accessed using WordPress XMLRPC.

It takes the following parameters

  1. appkey: ignored (pass some blank value)
  2. blogid (It’s not used)
  3. username,
  4. password
  5. count

The following program illustrates 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.getRecentPosts request which takes following parameters
 appkey: ignored (pass some blank value)
 blogid (It's not used)
function blogger_getRecentPosts($appkey,$blogid, $username, $password, $count) {
   global $BLOGURL;
   $request = xmlrpc_encode_request("blogger.getRecentPosts",
      array($appkey,$blogid, $username, $password, $count));
    /*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*/

$blogid = 1;
$USERNAME = "admin";
$PASSWORD = "check";
$count = 3; 

blogger_getRecentPosts($appkey, $blogid, $USERNAME, $PASSWORD, $count);
echo "n";

On running this above program,
$ php blogger.getRecentPosts.php
<?xml version="1.0"?>
<member><name>content</name><value><string>&lt;title&gt;check a post&lt;/title&gt;&lt;category&gt;1&lt;/category&gt;</string></value></member>
<member><name>content</name><value><string>&lt;title&gt;Hello world!&lt;/title&gt;&lt;category&gt;1&lt;/category&gt;Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</string></value></member>

As you can see, you can see the contents of a Post, its PostID, the date created and the userID who created the 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