Most modern blogging engines support the MetaWeblog API, which was defined by XML-RPC.com many years ago. It's become one of the most popular API's for programmatically interacting with blogs because of its simplicity. Even Microsoft's Windows Live Spaces provides support for it.
I wanted to use this API recently to interact with our Community Server implementation so I started searching around for client-side implementations that would be easy to program in C#. I was surprised that I couldn't find a mainstream implementation readily available. So I followed the example on MSDN and built my own MetaWeblog library in C# on top of Cook Computing's XML-RPC.NET library.
Here's what my MetaWeblogClient class looks like (truncated for brevity):
public class MetaWeblogClient : XmlRpcClientProtocol { [XmlRpcMethod("metaWeblog.getRecentPosts")] public Post[] getRecentPosts(string blogid, string username, string password, int numberOfPosts) { return (Post[])this.Invoke("getRecentPosts",
new object[] { blogid, username, password, numberOfPosts }); } [XmlRpcMethod("metaWeblog.newPost")] public string newPost(string blogid, string username, string password, Post content, bool publish) { return (string)this.Invoke("newPost",
new object[] { blogid, username, password, content, publish }); }
...
With this class, you can simply make method calls like getRecentPosts, newPost, editPost, etc to interact with any blog that supports the MetaWeblog API. You will need to specify that URL to the MetaWeblog endpoint prior to making those method calls. Here's an example:
class Program { static void Main(string[] args) { MetaWeblogClient blog = new MetaWeblogClient(); blog.Url = "http://www.pluralsight.com/community/blogs/metablog.ashx"; // here's how you post a new entry... Post newPost = new Post(); newPost.dateCreated = DateTime.Now; newPost.title = "Test post from Metablog Api"; newPost.description = "This is the body of the post"; newPost.categories = new string[] { "WCF", "WF" }; blog.newPost("blogid", "username", "password", newPost, true); // here's how you retrieve the most recent entries... Post[] posts = blog.getRecentPosts("blogid", "username", "password", 5); foreach (Post post in posts) Console.WriteLine(post.title); } }
The code turns out to be wonderfully simple. So if you find yourself in the same boat as me, looking for a MetaWeblog C# implementation, feel free to download my library here. Hopefully it will save you a little bit of time!