== 这是 中国WEB信息博物馆Web InfoMall 2004年05月24日 存储的网页 ==
点击这里查看本网页的其他版本 隐藏InfoMall信息

竹笋炒肉: MT的XML-RPC API

October 14, 2003

MT的XML-RPC API

  jedi译的MT手册中,没有这一章,下面MT实现的xml-rpc服务器端的API的学习笔记。

  除了因为Blogger和MT的模板系统的差异,getTemplate和setTemplate两个方法没有被支持外,MT支持Blogger XML-RPC API的其它全部方法。类似的,MT也支持metaWeblog XML-RPC API。另外,MT还增加了一些自己的方法,来操作文章(entry)的分类信息(category)。
  使用这些XML-RPC API,要求在服务器端安装LWP::UserAgent 和 SOAP::Lite两个perl模块。同时,建议将XML::Parser模块的也升级到最新版,较低的版本对非ascii的编码支持有问题。
附表:  Mt支持的xml-rpc方法
方法参数返回值说明备注
blogger.newPostString appkey String blogid String username String password String content boolean publish成功返回PostID,失败返回xml-rpc fault.新建一篇文章,根据设置决定是否发布在MT的实现中,所有appkey值都被忽略
blogger.editPostString appkey String postid String username String password String content boolean publish成功返回布尔真值,失败返回xml-rpc fault.更新一篇已存在的文章的信息
blogger.deletePostString appkey String postid String username String password boolean publish成功返回布尔真值,失败返回xml-rpc fault.删除一篇文章
blogger.getRecentPostsString appkey String blogid String username String password int numberOfPosts成功返回一个数据结构的数组,数据结构包括ISO.8601 dateCreated, String userid, String postid, String content,失败返回xml-rpc fault.返回最近的文章的列表
blogger.getUsersBlogsString appkey String username String password成功返回一个数据结构的数组,数据结构包括String url, String blogid, String blogName,失败返回xml-rpc fault.返回该用户用发表权限的blog的列表
blogger.getUserInfoString appkey String username String password成功返回一个数据结构,包括String userid, String firstname, String lastname, String nickname, String email, String url,失败返回xml-rpc fault.返回用户的信息firstname指username中第一个空格前的字符串,之后的为lastname





metaWeblog.newPostString blogid String username String password struct content boolean publish成功返回PostID,失败返回xml-rpc fault.新建一篇文章,根据设置决定是否发布content数据结构可包含下列标准键值(key): title, 文章标题 description, 文章的主要本体(body) dateCreated, 文章创建时间 下列键值是MT扩展的。 int mt_allow_comments, 字段allow_comments的值 int mt_allow_pings, 字段allow_pings的值 String mt_convert_breaks, 字段convert_breaks的值 String mt_text_more, 额外文章内容 String mt_excerpt, 摘要字段的内容 String mt_keywords, 关键字字段的内容 array mt_tb_ping_urls, 这篇文章需要通知的引用文章(TrackBack ping URLs)列表 如果指定了dateCreated则其格式为ISO.8601规定的格式.
metaWeblog.editPostString postid String username String password struct content boolean publish成功返回布尔真值,失败返回xml-rpc fault.更新一篇已存在的文章的信息content数据结构可包含下列标准键值(key): title, 文章标题 description, 文章的主要本体(body) dateCreated, 文章创建时间 下列键值是MT扩展的。 int mt_allow_comments, 字段allow_comments的值 int mt_allow_pings, 字段allow_pings的值 String mt_convert_breaks, 字段convert_breaks的值 String mt_text_more, 额外文章内容 String mt_excerpt, 摘要字段的内容 String mt_keywords, 关键字字段的内容 array mt_tb_ping_urls, 这篇文章需要通知的引用文章(TrackBack ping URLs)列表 如果指定了dateCreated则其格式为ISO.8601规定的格式.
metaWeblog.getPostString postid String username String password成功返回一个数据结构,包括String userid, ISO.8601 dateCreated, String postid, String description, String title, String link, String permaLink, String mt_excerpt, String mt_text_more, int mt_allow_comments, int mt_allow_pings, String mt_convert_breaks, String mt_keywords;,失败返回xml-rpc fault.返回指定的文章的信息
metaWeblog.getRecentPostsString blogid String username String password int numberOfPosts成功返回一个数据结构的数组,数据结构包括ISO.8601 dateCreated, String userid, String postid, String description, String title, String link, String permaLink, String mt_excerpt, String mt_text_more, int mt_allow_comments, int mt_allow_pings, String mt_convert_breaks, String mt_keywords;,失败返回xml-rpc fault.返回最近的文章的列表link和 permaLink 都指向这篇文章。
metaWeblog.newMediaObjectString blogid String username String password struct file返回上传文件的URL上传一个文件到web服务器file的结构包含两个键值: base64 bits (base64编码的文件内容) String name (文件名). 键值type(文件的媒体类型)目前被忽略.





mt.getRecentPostTitlesString blogid String username String password int numberOfPosts成功返回一个数据结构的数组,数据结构包括ISO.8601 dateCreated, String userid, String postid, String title,失败返回xml-rpc fault.返回最近文章的标题的列表,只返回标题而无其它内容主要为了减少带宽的占用
mt.getCategoryListString blogid String username String password成功返回一个数据结构的数组,数据结构包括String categoryId and String categoryName,失败返回xml-rpc fault.返回blog中的分类的列表
mt.getPostCategoriesString postid String username String password成功返回一个数据结构的数组,数据结构包括String categoryName, String categoryId, and boolean isPrimary,失败返回xml-rpc fault.返回该文章所属的类别IsPrimary用来指明某类别是不是它的主类别
mt.setPostCategoriesString postid String username String password array categories成功返回布尔真值,失败返回xml-rpc fault.设置一篇文章所属的类别category是个数据结构包含String categoryId and boolean isPrimary. isPrimary是可选的,用来设定主类别的,如果它被省略,则数组中第一个结构所指定的类别为其主类别.
mt.supportedMethods
方法名字的数组返回服务器所支持的xml-rpc方法的信息
mt.supportedTextFilters
成功返回一个数据结构的数组,数据结构包括String key and String label返回服务器支持的文本格式化插件的信息key 是区分文本格式化插件的唯一字符串, label 显示给用户的对文本格式化插件的描述。 key 的值可以做newPost或 editPost方法中 mt_convert_breaks 参数的值
mt.getTrackbackPingsString postid成功返回一个数据结构的数组,数据结构包括String pingTitle (通知的目标文章的标题) String pingURL (目标文章的URL) and String pingIP (目标主机的IP地址).返回指文章的TrackBack pings 列表
mt.publishPostString postid String username String password成功返回布尔真值,失败返回xml-rpc fault.发布一篇文章,同时重建相关的静态页面,除了不向外发通知外,如同通过web页面发布时点击“保存”按钮所产生的效果。

参考资料
http://www.movabletype.org/docs/mtmanual_programmatic.html#xmlrpc%20api


说明此文件是利用下列代码发布的。(filename即本文的文件名字)

import xmlrpclib, sys
BLOGID=1
LOGIN="myname"
PASSWORD="mypassword"
s = xmlrpclib.Server('http://hedong.3322.org/mypath/mt-xmlrpc.cgi')
filename=sys.argv[1]
try:
f = open(filename)
title=f.readline()
body=f.readline()
contents = f.read()
f.close()

postid=s.metaWeblog.newPost(BLOGID, LOGIN, PASSWORD, {
'title': title,
'description': body,
'mt_text_more': contents,
});
s.mt.setPostCategories(postid,LOGIN,PASSWORD,[{
'categoryId':1,
}]);
s.mt.publishPost(postid,LOGIN,PASSWORD);
except:
sys.exit(1)


另外一个例程
import xmlrpclib, sys
BLOGID=0
LOGIN="yourname"
PASSWORD="yourpassword"
s = xmlrpclib.Server('http://yourhost.com/yourpathtoMT/mt-xmlrpc.cgi')
print "blogger.getUserInfo"
userInfo=s.blogger.getUserInfo("",LOGIN,PASSWORD);
print userInfo
blogs=s.blogger.getUsersBlogs("",LOGIN,PASSWORD)
print blogs
for blog in blogs:
posts=s.blogger.getRecentPosts("",blog['blogid'],LOGIN,PASSWORD,10)
print "blog no=", blog['blogid']
print "-------------------------------"
for post in posts:
print "post no=",post['postid'],'date=',post['dateCreated']
print post['content']
post=s.metaWeblog.getPost(210,LOGIN,PASSWORD)
print post

Posted by Hilton at October 14, 2003 11:31 PM | TrackBack
Comments

asdfsad

Posted by: a at February 14, 2004 09:36 PM

dd

Posted by: d at October 30, 2003 08:26 PM

  由于html显示的原因,第一段代码中try:后面到except:前面的几行,要向右缩进。expcept后面几行,也要向后缩进。
  此文中所有的代码都是用python写成。
第二段代码缩进要求如下:
for blog in blogs:
    posts=s.blogger.getRecentPosts("",blog['blogid'],LOGIN,PASSWORD,10)
    print "blog no=", blog['blogid']
    print "-------------------------------"
    for post in posts:
        print "post no=",post['postid'],'date=',post['dateCreated']
        print         post['content']

Posted by: Hilton at October 14, 2003 11:37 PM
Post a comment









Remember personal info?