apache xml-rpc metaWeblog api

Some irish guy wrote up a short blogging APIs mini how-to yesterday. Then some other guy from England (I think) commented that he had written up a quick example of using the apache xml-rpc package to call the metaWeblog api. So I had to try it too. Turns out that a) xml-rpc is really easy to do and b) the Moveable Type xml-rpc api is really easy too… the code below calls the getRecentPosts() method of the metaWeblog api using the apache xml-rpc package:

import org.apache.xmlrpc.*;
import java.util.*;
public class MTTest {
  public static void main(String[] args) throws Exception {

   System.out.println(“Starting Movable type stuff”);
   Vector params=null;

   // Create XML RPC Client object
   XmlRpcClient xmlrpc = new XmlRpcClient(“http://yourhost.com/MT-2.21/mt-xmlrpc.cgi”);

   // blogger.getRecentPosts
   // String appkey, String blogid, String username, String password, int numberOfPosts
   System.out.println(“Adding the parameters”);
   params = new Vector();
   params.add(“your_weblog_id”); // weblog id
   params.add(“yourusername”); // username
   params.add(“yourpassword”); // password
   params.add(“4”); // number of posts to retrieve…

   System.out.println(“Making the call”);
   Vector v = (Vector)xmlrpc.execute(“metaWeblog.getRecentPosts”,params);

   System.out.println(“This call results in ” + v.size() + ” posts.”);
   System.out.println(“These are the results:”);
    for (int i=0; i

Leave a Reply

Your email address will not be published. Required fields are marked *