In a previpus blog post we discussed how to consume the Technorati ping web service using XML-RPC. The PEAR package XML_RPC2 provides convenient client and server objects. You can call the remote methods as if they were the methods of the client object.
In this post, let us accomplish the same using a PEAR package XML_RPC2. We will write a client script to update Technorati when there is new post in your blog site.
Install the package using the PEAR installer.
pear install XML_RPC2
We are going to call the remote method weblogUpdates.ping with our site name and site URL as the parameters.
<?php
$server = 'http://rpc.technorati.com/rpc/ping';
$site_name = "Tech Chorus";
$site_url = "http://techchorus.net";
?>Create the XML-RPC client object.
<?php
require_once 'XML/RPC2/Client.php';
$options = array(
'prefix' => 'weblogUpdates.'
);
$client = XML_RPC2_Client::create($server, $options);
?>Since PHP does not support method names containing special characters like .(period), we specify 'weblogUpdates.' as an option while creating the $client object. Notice a .(period) in the $options array value for the key 'prefix'. We pass our site name and site URL as the parameters to the remote method.
Call the remote method weblogUpdates.ping.
<?php
$result = $client->ping($site_name, $site_url);
?>If the server method name did not contain the period special character, we didn't have to set the prefix key in the options array.
The $result variable now has the decoded response array.
If you print_r the $result array the output looks like
Array
(
[flerror] =>
[message] => Thanks for the ping
)With the PEAR package we could implement an XML-RPC client in less than ten lines of code.
The entire script is posted below.
<?php
$server = 'http://rpc.technorati.com/rpc/ping';
$site_name = "Tech Chorus";
$site_url = "http://techchorus.net";
require_once 'XML/RPC2/Client.php';
$options = array(
'prefix' => 'weblogUpdates.'
);
$client = XML_RPC2_Client::create($server, $options);
$result = $client->ping($site_name, $site_url);
?>You can also grab the script from the Code Album github repository.
Pinr custom site
Can we use this to ping for custom sites instead of blog ?
Nothing stops you from doing
Nothing stops you from doing it. But Technorati is focused on blogs.
i enjoy your article. great
i enjoy your article. great job.
How would we include the rss
How would we include the rss url of oir site, for other rpc ping services?
Post new comment