使用WordPress的XMLRPC功能

WordPress 内部就有XMLRPC功能,稍作修改,就可以通过XMLRPC服务达到不少高级的功能,比如两个Blogger站点内容进行同步,只要另一个支持 XMLRPC发布就行。My Donews就支持XMLRPC发布,比如我这篇文章,就是用Zoundry这个软件离线写作,然后发到网上的。

下面的代码来自http://hasin.wordpress.com/2006/07/15/using-blog-apis/

这个地方也许国内无法访问,所以把文章拷贝过来了。

Almost every standard compliant blogs support three blogging API which are “Blogger API” , “MovableType API” and “MetaWeblog API”. Among these MW (or MetaWeblog) is used more than other two. Wordpress also supporst these three sets of API. If you are interesetd how to interact with these API’s - then take a look at the following example.

First lets discover which XMLRPC methods are suported by wordpress XMLRPC server. Just execute the following script

system.multicall
system.listMethods
system.getCapabilities
demo.addTwoNumbers
demo.sayHello
pingback.extensions.getPingbacks
pingback.ping
mt.publishPost
mt.getTrackbackPings
mt.supportedTextFilters
mt.supportedMethods
mt.setPostCategories
mt.getPostCategories
mt.getRecentPostTitles
mt.getCategoryList
metaWeblog.getUsersBlogs
metaWeblog.setTemplate
metaWeblog.getTemplate
metaWeblog.deletePost
metaWeblog.newMediaObject
metaWeblog.getCategories
metaWeblog.getRecentPosts
metaWeblog.getPost
metaWeblog.editPost
metaWeblog.newPost
blogger.deletePost
blogger.editPost
blogger.newPost
blogger.setTemplate
blogger.getTemplate
blogger.getRecentPosts
blogger.getPost
blogger.getUserInfo
blogger.getUsersBlogs

so to make a new post using metaWeblog.newPost method lets take a look at the following example.

<?php
 include("xmlrpc.inc.php");
 $c = new xmlrpc_client("/wp/xmlrpc.php", "localhost", 80);

 $content['title']="XMLRPC Post";
 $content['description']="Some content posted using MetaWeblog API";
 $content['categories'] = array("frontpage");
 $x = new xmlrpcmsg("metaWeblog.newPost",
                     array(php_xmlrpc_encode("1"),
                        php_xmlrpc_encode("admin"),
                        php_xmlrpc_encode("root"),
                        php_xmlrpc_encode($content),
                        php_xmlrpc_encode("1")));

 $c->return_type = 'phpvals';
 $r =$c->send($x);
 if ($r->errno=="0")
 echo "Successfully Posted";
 else {
  echo "There are some error";
  print_r($r);
              }
?>
相关帖子:
  • No Related Posts
  • micas Jul 31st 2007 05:11 pm SEO No Comments yet Trackback URI Comments RSS

    Leave a Reply

    You must be logged in to post a comment.