It’s been quite a while since I’ve done any work on the blog.  However, with the recent switch over to working on iPhone development at work, I have to get my .Net in somewhere.  Trying to keep in line with the agenda I had originally set, I’m going to cover adding a MetaWeblog API to the blog.  MetaWeblog API is an interface for allowing external programs to get and set posts for a web site.  Basically it allows an easy way to post content to a blog.  In addition, there are blog editors (like Windows Live Writer) that can easily interface using this API.  This just saves us from having to make a fancy pants post creator in the admin section of the web site until much later.  We’re going to be using the CookComputing XmlRpc V2 dll for this.  You can get the latest version of it by going here.  We’ll add this in to our references.  In order to use the MetaWeblog API, we have to put all the methods into an endpoint or somewhere they can receive communication.  We’re going to put everything into a Generic Handler:

After we create this, we have a mess of methods to add to fit the MetaWeblog spec:

   1:  string IMetaWeblog.AddPost(string blogid, string username, string password,
   2:      Post post, bool publish)
   3:  {}
   5:  bool IMetaWeblog.UpdatePost(string postid, string username, string password,
   6:      Post post, bool publish)
   7:  {}
   9:  Post IMetaWeblog.GetPost(string postid, string username, string password)
  10:  {}
  12:  CategoryInfo[] IMetaWeblog.GetCategories(string blogid, string username, string password)
  13:  {}
  15:  Post[] IMetaWeblog.GetRecentPosts(string blogid, string username, string password,
  16:      int numberOfPosts)
  17:  {}
  19:  MediaObjectInfo IMetaWeblog.NewMediaObject(string blogid, string username, string password,
  20:      MediaObject mediaObject)
  21:  {}
  23:  bool IMetaWeblog.DeletePost(string key, string postid, string username, string password, bool publish)
  24:  {}
  26:  BlogInfo[] IMetaWeblog.GetUsersBlogs(string key, string username, string password)
  27:  {}
  29:  UserInfo IMetaWeblog.GetUserInfo(string key, string username, string password)
  30:  {}

I won’t bother explaining what all of these methods do.  The names should mostly explain it (and if not you can go through the code).  Here we have methods for adding, updating, deleting, and getting posts, getting user info, and uploading media items.  Basically, when you use an editor like Live Writer that works with MetaWeblog, you can add posts, images, videos, etc to your blog using just these methods.  With this done, we can actually add content to our web site.  Down the road, we’ll add the ability to do this from an admin portal, but initially we’ll just use this.  As always, you can download the latest code here.

Chris Risner

Leave a Comment