Page 1 of 1

Trying to find the right way to use XML-RPC

Posted: Fri Jan 11, 2008 7:50 pm
by cacimar
Below is a ruby script I'm using to call the Joomla XML-RPC Blogger API.

All functions work except the call to blogger.newPost

It returns an error from Joomla: XMLRPC::FaultException: Post check failed
(Error generated from the logic in plgins/xmrpc/blogger.php  line 215)

Any ideas on the problem or working examples of open code which successfully uses the xml-rpc blogger api?


require 'xmlrpc/client'

# Sets server to my site
server = XMLRPC::Client.new2('http://mysite.com/xmlrpc/index.php')

# function getUserInfo($appkey, $username, $password)
result = server.call('blogger.getUserInfo','unused_appkey','admin','password')
puts result

# function getRecentPosts($appkey, $blogid, $username, $password, $numposts)
result = server.call('blogger.getRecentPosts','unused_appkey','unused_blogid','admin','password',9)
puts result

# function newPost($appkey, $blogid, $username, $password, $content, $publish)
server.call('blogger.newPost','unused_appkey','unused_blogid','admin','password','Post This', true)

Re: Trying to find the right way to use XML-RPC

Posted: Fri Jan 11, 2008 8:02 pm
by AmyStephen
I do not know of anyone successfully using it. There have been many saying they want to use it.

To the best of my knowledge, it's not had much developer attention for a long time, nor do I believe it will have any before v 1.5 goes live.

In my opinion, this solution will need to come from our community.

Thanks!
Amy :)

Re: Trying to find the right way to use XML-RPC

Posted: Fri Jan 11, 2008 8:19 pm
by cacimar
I've seen some confusing messages from  the recent threads on it.  It seemed they said the Blogger API as existed worked in Joomla. Maybe I'll brave that other thread to clarify.

I'll be working on something next month and am trying to ramp up and check existing functionality to have a good base to start. 

Re: Trying to find the right way to use XML-RPC

Posted: Fri Jan 11, 2008 8:37 pm
by AmyStephen
Almost two years ago, Johan added Blogger API v 1 to Joomla! v 1.5. That's the pieces you are working with. It really should be updated to 2.0.

There is some code started on a MetaWeblog API that there was just no time to finish. That might provide someone a place to start with that API.

Make certain to check the Extensions Directory, as well. There's a lot of interest, of course, in this area.

HTH,
Amy :)

Re: Trying to find the right way to use XML-RPC

Posted: Fri Jan 11, 2008 9:15 pm
by cacimar
Amy,
Thanks for your help.  I'll look at the MetaWebBlog stuff.

After an afternoon cup of coffee, I discovered the Blogger API needed a tag in the last parameter. <br /><br /><br />The following works<br /><br /><br /><div class="codebox"><p>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code><br /># function newPost($appkey, $blogid, $username, $password, $content, $publish)<br />result = server.call('blogger.newPost','unused_appkey','unused_blogid','admin','password','<title>Test Title</test>This shows up in the body<strong>So does this in bold</strong>', false)<br /><br /></code></pre></div></div> </div> <hr /> <div class="post"> <h3>Re: Trying to find the right way to use XML-RPC</h3> <div class="date">Posted: <strong>Fri Jan 11, 2008 11:48 pm</strong></div> <div class="author">by <strong>AmyStephen</strong></div> <div class="content">Does that completely resolve the problem, and now the Blogger API for xml-rpc is usable?<br /><br />If so, let's get that patch moving into core.</div> </div> <hr /> <div class="post"> <h3>Re: Trying to find the right way to use XML-RPC</h3> <div class="date">Posted: <strong>Sat Jan 12, 2008 12:26 am</strong></div> <div class="author">by <strong>cacimar</strong></div> <div class="content">I only changed how I was using existing code.  In other words, I was using Joomla wrong - but it is also undocumented.  <br />No change to Joomla.<br /><br />I'm going to tinker with it more and try to summarize what I've found.  The initial problem I'm trying to solve is "documenting existing functionality."  I'm interesting in expanding the functionality, but I need to figure where we are first.<br /><br />I have a specific need I'll have to work towards first, which is massive importing from xml exported from another common program (deadlining in February) - but I honestly believe the functionality will require fleshing out something already existing and taking advantage of it, so hopefully I'll at least be able to  document it for people to take advantage of.  I get the impression people are really looking for a full implementation of a common API used by the many clients out there. <br /><br />But, right now, as Joomla is, you can programatically:<br />-getRecentPosts<br />-newPost - post uncategorized messages<br />-getUserInfo<br /><br />untested but things appear to be in order:<br />deletePost<br />editPost<br />getPost<br /><br />I believe is irrelevant:<br />getUserBlogs</div> </div> <hr /> <div class="post"> <h3>Re: Trying to find the right way to use XML-RPC</h3> <div class="date">Posted: <strong>Sat Jan 12, 2008 12:47 am</strong></div> <div class="author">by <strong>AmyStephen</strong></div> <div class="content">That is great! Anything you can shout out on that topic, from time to time will be appreciated. I hope others interested might also join in and you could learn from one another. <br /><br />Good stuff. Appreciate it very much. <br />Amy <img class="smilies" src="./images/smilies/smiley.gif" alt=":)" title="Smiley" /></div> </div> <hr /> <div class="post"> <h3>Re: Trying to find the right way to use XML-RPC</h3> <div class="date">Posted: <strong>Tue Jan 15, 2008 7:30 pm</strong></div> <div class="author">by <strong>cacimar</strong></div> <div class="content">Below is a list of the functions and working ruby examples.  Some comments included.  Some more work to be done<br /><br /><div class="codebox"><p>Code: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>require 'xmlrpc/client'<br /><br /># Sets server to my site<br />server = XMLRPC::Client.new2('http://joomla.drapetomanics.com/xmlrpc/index.php')<br /><br />##  function getUserBlogs($appkey, $username, $password)<br />##  Errors out - irrelevant<br /><br /># result = server.call('blogger.getUserBlogs','unused_appkey','admin','password')<br /># puts result <br /><br /><br />##  function getUserInfo($appkey, $username, $password)<br />result = server.call('blogger.getUserInfo','unused_appkey','admin','password')<br />puts result<br /><br />##  function getPost($appkey, $postid, $username, $password)<br /><br />result = server.call('blogger.getPost','unused_appkey','1','admin','password')<br />puts result<br /><br /><br />##  function editPost($appkey, $postid, $username, $password, $content, $publish)<br /><br />result = server.call('blogger.editPost','unused_appkey','2','admin','password','<titel>new content</title>content',true)<br />puts result<br /><br />## XMLRPC::FaultException: Post check failed 2<br /><br /><br />##  function deletePost($appkey, $postid, $username, $password, $publish)<br />result = server.call('blogger.deletePost','unused_appkey','1','admin','password',false)<br />puts result<br /><br />#Missing return value initially<br />#no post afterwards<br /><br /><br /><br />## function getRecentPosts($appkey, $blogid, $username, $password, $numposts)<br />result = server.call('blogger.getRecentPosts','unused_appkey','unused_blogid','admin','password',9)<br />puts result<br /><br /><br />##  function getTemplate($appkey, $blogid, $username, $password, $templateType)<br />## not implemented<br /><br /><br />##  function newPost($appkey, $blogid, $username, $password, $content, $publish)<br />result = server.call('blogger.newPost','unused_appkey','unused_blogid','admin','password','<title>Test Title4</title>test body<strong>bold</strong>', false)<br />puts result</code></pre></div></div> </div> <hr /> <div class="post"> <h3>Re: Trying to find the right way to use XML-RPC</h3> <div class="date">Posted: <strong>Wed Jan 16, 2008 3:02 pm</strong></div> <div class="author">by <strong>aini</strong></div> <div class="content">Great, cacimar !!<br /><br />I would love to add some optional things in postNews function  <img class="smilies" src="./images/smilies/wink.gif" alt=";)" title="Wink" /><br /><br />result = server.call('blogger.newPost','unused_appkey','unused_blogid','admin','password','<title>Test Title4The CMStest bodyboldmore and more ', false)
puts result

You can see all this stuff in joomladir/plugins/xmlrpc/blogger.php

Re: Trying to find the right way to use XML-RPC

Posted: Wed Jan 16, 2008 3:08 pm
by cacimar
Aini,
When I tested the newPost before - and< more text>didn't seem to work..  The information seemed to go nowhere..  I haven't traced down the functionality there yet.

Re: Trying to find the right way to use XML-RPC

Posted: Thu Jan 17, 2008 4:28 am
by aini
could you attach your ruby code project ?

I will check it ...

Re: Trying to find the right way to use XML-RPC

Posted: Thu Jan 17, 2008 5:23 am
by AmyStephen
Rich -

You really lucked out. You have a core developer paying attention to your project. I guess you show a little promise!

Thanks, Aini!
Amy :)

Re: Trying to find the right way to use XML-RPC

Posted: Mon Jan 21, 2008 4:58 pm
by cacimar
aini,
I've attached my basic ruby testing script.

The very last call is the attempt to post.  seems to go nowhere  and   doesn't appear to affect the category or section the new article is assigned to.

I mentioned earlier in the thread, I'm working on this now only in the background, but in early February I'll be working on it more with the hopes of transforming archived xml data (from Adobe inDesign) to a format useable by Joomla and posting it.

Re: Trying to find the right way to use XML-RPC

Posted: Wed Jan 23, 2008 1:57 pm
by aini
Hi Rich,

Well, I fully understand
It was Joomla bugs

I will fix the bug tomorrow  ;)

It sounds you have been working interesting stuff

Thanks in advance

Re: Trying to find the right way to use XML-RPC

Posted: Wed Jan 23, 2008 2:48 pm
by cacimar
Thanks Aini,
Maybe after I see your changes, I'll be able to see enough to contribute more to that area as well.

Re: Trying to find the right way to use XML-RPC

Posted: Thu Jan 24, 2008 3:52 am
by aini
I have put the patch in Joomla Tracker http://joomlacode.org/gf/project/joomla ... em_id=9399

Waiting Q&T to check it

Here is my following patch, You can test it in your PC

Code: Select all

Index: /data1/trunk/plugins/xmlrpc/blogger.php
===================================================================
--- /data1/trunk/plugins/xmlrpc/blogger.php   (revision 9962)
+++ /data1/trunk/plugins/xmlrpc/blogger.php   (working copy)
@@ -428,8 +428,9 @@
       $match = array();
       if ( preg_match('/<more_text>(.+?)<\/more_text>/is', $content, $match) )
       {
-         $fulltext = trim($match[1], ',');
-         $fulltext = explode(',', $fulltext);
+         $fulltext = $match[0];
+         $fulltext = preg_replace('/<more_text>/si', '', $fulltext);
+         $fulltext = preg_replace('/<\/more_text>/si', '', $fulltext);
       }
 
       return $fulltext;



Anyway, for category tag, it is configured by default at blogger plugin configuration

You can see this following code :

Code: Select all

// load the category
$cat =& JTable::getInstance('category');
$cat->load($params->get( 'catid', 1 ));


I will ask in J!Dev List whether we could define any category through XML-RPC
That would be more nice  :-*