MetaWeblog API调用
2012-05-04 17:36
597 查看
在网上闲逛,突然对博客的接口感兴趣,经考察,多数博客都对metaWeblog Api 提供了支持,虽然windows live writer是好用,不过出于对这个接口的好奇,也想自己做个能发博客的小工具.
到处浏览资料,用了一个下午终于成功发布了一篇简陋版博客:)。其实很简单,方法对了很快就连上了。
MetaWeblog API中文说明
1、什么是MetaWeblog API?
MetaWeblog API(MWA)是一个Blog程序接口标准,允许外部程序来获取或者设置Blog的文字和熟悉。他建立在XMLRPC接口之上,并且已经有了很多的实现。
2、基本的函数规范
有三个基本的函数规范:
metaWeblog.newPost (blogid, username, password, struct, publish) 返回一个字符串,可能是Blog的ID。
metaWeblog.editPost (postid, username, password, struct, publish) 返回一个Boolean值,代表是否修改成功。
metaWeblog.getPost (postid, username, password) 返回一个Struct。
其中blogid、username、password分别代表Blog的id(注释:如果你有两个Blog,blogid指定你需要编辑的blog)、用户名和密码。
下载 CookComputting.XmlRpc.dll
二、要实现的数据结构
MetaWeblogCode【如不想看代码请自行折叠】
三、图示【调用API发送第一篇简单博客】
到处浏览资料,用了一个下午终于成功发布了一篇简陋版博客:)。其实很简单,方法对了很快就连上了。
MetaWeblog API中文说明
1、什么是MetaWeblog API?
MetaWeblog API(MWA)是一个Blog程序接口标准,允许外部程序来获取或者设置Blog的文字和熟悉。他建立在XMLRPC接口之上,并且已经有了很多的实现。
2、基本的函数规范
有三个基本的函数规范:
metaWeblog.newPost (blogid, username, password, struct, publish) 返回一个字符串,可能是Blog的ID。
metaWeblog.editPost (postid, username, password, struct, publish) 返回一个Boolean值,代表是否修改成功。
metaWeblog.getPost (postid, username, password) 返回一个Struct。
其中blogid、username、password分别代表Blog的id(注释:如果你有两个Blog,blogid指定你需要编辑的blog)、用户名和密码。
下载 CookComputting.XmlRpc.dll
二、要实现的数据结构
MetaWeblogCode【如不想看代码请自行折叠】
using System; using CookComputing.XmlRpc; namespace metaWeblogTest { #region 微软MSN网站 使用的 MetaWeblog API. /// 这个结构代表用户的博客基本信息 /// </summary> [XmlRpcMissingMapping(MappingAction.Ignore)] public struct UserBlog { public string url; public string blogid; public string blogName; } /// <summary> /// 这个结构代表用户信息 /// </summary> [XmlRpcMissingMapping(MappingAction.Ignore)] public struct UserInfo { public string url; public string blogid; public string blogName; public string firstname; public string lastname; public string email; public string nickname; } /// <summary> /// 这个结构代表博客分类信息 /// 这后面的getCategories()方法会取到CATEGORY数据。 /// </summary> [XmlRpcMissingMapping(MappingAction.Ignore)] public struct Category { public string description; public string title; } /// <summary> /// 这个结构代表博客( 文章 )信息。 /// 这后面的 editPost()方法, getRecentPosts()方法 和 getPost()方法 会取倒POST数据 . /// </summary> [XmlRpcMissingMapping(MappingAction.Ignore)] public struct Post { public DateTime dateCreated; public string description; public string title; public string postid; public string[] categories; } #endregion #region 网站:http://msdn.microsoft.com/en-us/library/aa905670.aspx ///// <summary> ///// 微软MSN网站 使用的 MetaWeblog API. //// 网站:http://msdn.microsoft.com/en-us/library/aa905670.aspx ///// </summary> public class M_MetaWeblog : XmlRpcClientProtocol { /// <summary> /// Returns the most recent draft and non-draft blog posts sorted in descending order by publish date. /// </summary> /// <param name="blogid"> This should be the string MyBlog, which indicates that the post is being created in the user’s blog. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"> The user’s secret word. </param> /// <param name="numberOfPosts"> The number of posts to return. The maximum value is 20. </param> /// <returns></returns> /// TODO:得到最近发布的帖子 [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 }); } /// <summary> /// Posts a new entry to a blog. /// </summary> /// <param name="blogid"> This should be the string MyBlog, which indicates that the post is being created in the user’s blog. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"> The user’s secret word. </param> /// <param name="post"> A struct representing the content to update. </param> /// <param name="publish"> If false, this is a draft post. </param> /// <returns> The postid of the newly-created post. </returns> /// TODO:增加一个最新的帖子 [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 }); } /// <summary> /// Edits an existing entry on a blog. /// </summary> /// <param name="postid"> The ID of the post to update. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"> The user’s secret word. </param> /// <param name="post"> A struct representing the content to update. </param> /// <param name="publish"> If false, this is a draft post. </param> /// <returns> Always returns true. </returns> /// TODO:更新一个帖子 [XmlRpcMethod("metaWeblog.editPost")] public bool editPost( string postid, string username, string password, Post content, bool publish) { return (bool)this.Invoke("editPost", new object[] { postid, username, password, content, publish }); } /// <summary> /// Deletes a post from the blog. /// </summary> /// <param name="appKey"> This value is ignored. </param> /// <param name="postid"> The ID of the post to update. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"> The user’s secret word. </param> /// <param name="post"> A struct representing the content to update. </param> /// <param name="publish"> This value is ignored. </param> /// <returns> Always returns true. </returns> /// TODO:删除一个帖子 [XmlRpcMethod("blogger.deletePost")] public bool deletePost( string appKey, string postid, string username, string password, bool publish) { return (bool)this.Invoke("deletePost", new object[] { appKey, postid, username, password, publish }); } /// <summary> /// Returns information about the user’s space. An empty array is returned if the user does not have a space. /// </summary> /// <param name="appKey"> This value is ignored. </param> /// <param name="postid"> The ID of the post to update. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"></param> /// <returns> An array of structs that represents each of the user’s blogs. The array will contain a maximum of one struct, since a user can only have a single space with a single blog. </returns> /// TODO:得到用户的博客清单 [XmlRpcMethod("blogger.getUsersBlogs")] public UserBlog[] getUsersBlogs( string appKey, string username, string password) { return (UserBlog[])this.Invoke("getUsersBlogs", new object[] { appKey, username, password }); } /// <summary> /// Returns basic user info (name, e-mail, userid, and so on). /// </summary> /// <param name="appKey"> This value is ignored. </param> /// <param name="postid"> The ID of the post to update. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"></param> /// <returns> A struct containing profile information about the user. /// Each struct will contain the following fields: nickname, userid, url, e-mail, /// lastname, and firstname. </returns> /// TODO:得到用户信息 [XmlRpcMethod("blogger.getUserInfo")] public UserInfo getUserInfo( string appKey, string username, string password) { return (UserInfo)this.Invoke("getUserInfo", new object[] { appKey, username, password }); } /// <summary> /// Returns a specific entry from a blog. /// </summary> /// <param name="postid"> The ID of the post to update. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"> The user’s secret word. </param> /// <returns> Always returns true. </returns> /// TODO:获取一个帖子 [XmlRpcMethod("metaWeblog.getPost")] public Post getPost( string postid, string username, string password) { return (Post)this.Invoke("getPost", new object[] { postid, username, password }); } /// <summary> /// Returns the list of categories that have been used in the blog. /// </summary> /// <param name="blogid"> This should be the string MyBlog, which indicates that the post is being created in the user’s blog. </param> /// <param name="username"> The name of the user’s space. </param> /// <param name="password"> The user’s secret word. </param> /// <returns> An array of structs that contains one struct for each category. Each category struct will contain a description field that contains the name of the category. </returns> /// TODO:得到博客分类 [XmlRpcMethod("metaWeblog.getCategories")] public Category[] getCategories( string blogid, string username, string password) { return (Category[])this.Invoke("getCategories", new object[] { blogid, username, password }); } } #endregion }
三、图示【调用API发送第一篇简单博客】
相关文章推荐
- MetaWeblog API调用
- 常用博客Metaweblog Api地址
- 在Asp.Net中创建MetaWeblog API
- 利用Metaweblog技术的API接口同步到多个博客网站(详细)
- 利用MetaWeblog API 自制博客发布小工具
- MetaWeblog API中文说明
- 转 MetaWeblog API 编写
- 把用octopress最新发布的博文同步到提供metaweblog API的博客(例如博客园)上
- MetaWeblog API
- MetaWeblog API中文说明
- metaweblog API csdn python实现
- 有关 Blogger API、MetaWeblog API、MovableType API的转帖3篇
- MetaWeblog API 测试!11111111111
- iOS 版 MWeb 发布到自建 Wordpress 和 Metaweblog API 使用指南
- 通知:Metaweblog API重新开放
- 常用博客Metaweblog Api地址
- 博客园Meta Weblog API增强建议
- 通知:Metaweblog API重新开放
- MetaWeblog API in Java
- MetaWeblog API on Nodejs