Almost every standard compliant blogs support three blogging API which are “Blogger API” , “MovableType API” and “MetaWeblog API”. Among these three, 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. After digging a bit further we found that the following methods are supported
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);
}
?>
Thats it!!














15 responses so far ↓
arild // July 30, 2006 at 7:10 pm
how do we make http://www.somewhereinblog.net open source and/or get api’s that people can stick up on their websites, both initiating reading and writing from that window? can we discuss about that soon?
hasin // July 31, 2006 at 9:24 am
isnt somewhereinblog based on wordpress 2.0? It is already opensource and support metaweblog API. All you need to develop a web based GUI for them. Or create user ID for each of them and inform their user ID. They can implement access our blog using Blog APIs.
have you ever been to http://m.wordpress.com [For mobile] ? We could have something like that.
mallcom // November 27, 2006 at 2:39 am
Hi,
where can I get ‘xmlrpc.inc.php’ and ‘/wp/xmlrpc.php’??
/wp/xmlrpc.php - is the same using by WordPress PHP Script??
To use this code I need xmlrpc_client CLASS, right??
I want to setup a simple PHP Script to load from RSS Feed and use MetaWeblog API to Post to some Blog.
I may use this Script????
Thanks in advance,
m.
hasin // November 27, 2006 at 8:17 am
@Mallcom
Yes you are right that you have to use an xml-rpc client. In the example shown above I used PHP XML-RPC package which is available from sourceforge at the following URL
http://phpxmlrpc.sourceforge.net/
You can use this script without any problem at all.
Regards
mallcomclips // November 29, 2006 at 2:18 am
Hi,
I get no response using this
return_type = ‘phpvals’;
$r =$c->send($x);
if ($r->errno==”0″)
echo “Successfully Posted”;
else {
echo “There are some error”;
print_r($r);
}
?>
I’m using xmlrpc.inc.php found at lib folder at xmlrpc-2.1 zip.
Is it allright??
thanks in advance hasin.
m.
Prashant // March 2, 2007 at 10:54 pm
Hello
I am Prashant from calcutta India.
I need your help in wordpress.
I have integrated WordPress in my site and now from here anyone can create new WPblog. Its working fine.
If my site is mysite.com then after creating WPblog the new blog url is abc.mysite.com.
Problem :
Now i am trying to use XML-RPC 2.2 and trying to fetch blogger information, its working fine if i am trying to fetch blogs which is under wordpress.com (hosted by others) but i am not able to fetch the same for my site!! ( I have .htaccess in my mysite.com site and from there i am redirecting my user to there blogs.) . Will you please tell me what the mistake i am doing here.
Error : When i am trying to fetch the “abc.mysite.com” then i am getting “404 not found” ,when i am doing abc.mysite.com/xmlrpc.php i am getting the msg : “XML-RPC server accepts POST requests only.”
I show this error in many site but not getting the solution. i hope i will get help soon!!!
Thanks
Prashant
hasin // April 16, 2007 at 6:37 pm
please trun on debug by writing $c->debug = true;
Then you can analyze what went wrong!
促能技术网:Enabling Technology » 使用WordPress的XMLRPC功能 // July 31, 2007 at 3:11 pm
[...] 下面的代码来自http://hasin.wordpress.com/2006/07/15/using-blog-apis/ [...]
TechNayak » Blog Archive » Using XMLRPC interface to Wordpress and Blogger // March 1, 2008 at 9:57 pm
[...] XML_RPC. Just download the XML-RPC implementation in php from here and follow the instructions in this article. That should just about do it , dont you think [...]
Ritesh // March 1, 2008 at 10:01 pm
Thanks you Hasin. I was struggling with Blogger API as the title wasn’t getting set when posting to wordpress. The code stub you gave works wonderfully well. Still have problems with the categories though. Couldnt figure that out. If you can mail me how to set categories in these posts, that would be lovely. Thanks a lot !! Cheers!!
Using XMLRPC interface to Wordpress and Blogger « Intelligent Quotes // March 2, 2008 at 1:04 pm
[...] XML_RPC. Just download the XML-RPC implementation in php from here and follow the instructions in this article. That should just about do it , dont you think [...]
Using XMLRPC interface to Wordpress and Blogger « TechNayak(mirror) // March 21, 2008 at 5:44 pm
[...] XML_RPC. Just download the XML-RPC implementation in php from here and follow the instructions in this article. That should just about do it , dont you think [...]
links for 2008-04-22 « Mo Hax // April 22, 2008 at 5:08 pm
[...] Using Blog API’s « The Storyteller This is a test [...]
agung // September 8, 2008 at 10:07 pm
Hi, do you any code that can be used to run getCategories?
Dam // September 28, 2008 at 7:08 pm
Hi Hasin,
thanks a lot for your example.
My question is: how do you get the allowed element lists to populate $content array (I mean … where is described the struct?)
thanks
Leave a Comment