Categories
PHP

Using Blog API's

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!!

41 replies on “Using Blog API's”

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.

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.

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.

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

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!!

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

This works great for my wordpress stuff, but I’m trying to figure out how to set the content such that it will schedule the post for a future date/time. Any ideas what I need to set in content?

Leave a Reply to Cexwrata Cancel reply

Your email address will not be published. Required fields are marked *