Thanks Eric! How did you handle the areguments with struct datatypes like for creating a new category? Do you just pass in a array with key=>val pairs or do you have to do special encoding?<div><br></div><div>Tim<br><br>
<div class="gmail_quote">On Tue, Jun 15, 2010 at 1:06 PM, <a href="mailto:eric@eamann.com">eric@eamann.com</a> <span dir="ltr"><<a href="mailto:eric@eamann.com">eric@eamann.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div>
<p style="margin:0px">OK, now I understand what you're doing.</p>
<p style="margin:0px"> </p>
<p style="margin:0px">When I first started working with WordPress and XMLRPC, I tried building my own library ... it was taking a long time, and I ran into many of the issues you're running in to now. Someone suggested I use the built-in IXR library instead, and it made all the difference.</p>
<p style="margin:0px"> </p>
<p style="margin:0px">Here's a simple example:</p>
<p style="margin:0px"> </p>
<p style="margin:0px">include_once(ABSPATH . WPINC . '/class-IXR.php');</p>
<p style="margin:0px"> </p>
<p style="margin:0px">$client = new IXR_Client('destinantion_url');</p>
<p style="margin:0px"> </p>
<p style="margin:0px">$client->query('<a href="http://procedure.name" target="_blank">procedure.name</a>', 'arg1', 'arg2', 'arg3', ...);</p>
<p style="margin:0px"> </p>
<p style="margin:0px">$response = $client->getResponse();</p>
<p style="margin:0px"> </p>
<p style="margin:0px">That will load the library, create a new client pointing at whatever WP installation you're working with, execute your remote procedure, and store the response (errors, data, or whatever) in the $response variable.</p>
<div><div></div><div class="h5">
<p style="margin:0px"> </p>
<p> </p>
<div style="margin:5px 0px 5px 0px;font-family:monospace">
On June 15, 2010 at 6:51 PM Tim Golen <<a href="mailto:tim@golen.net" target="_blank">tim@golen.net</a>> wrote:<br>
<br>
> Hi Joseph,<br>
><br>
> Right on, that's exactly what I needed to know.<br>
><br>
> I've been using <a href="http://devzone.zend.com/article/1307" target="_blank">http://devzone.zend.com/article/1307</a> for the XML-RPC (lower<br>
> level) API, and then building my own PHP library on top of that (with the<br>
> Wordpress functions). I'll go and check out the IXR library to see if that<br>
> helps.<br>
><br>
> All of the calls that I am making that pull data from Wordpress are working<br>
> fine. It's just when trying to create data (wp.newComment, wp.newCategory,<br>
> metaWeblog.newPost) they are all giving me similar data errors:<br>
><br>
> Sorry, the new category failed.<br>
><br>
> Invalid Data: Please go back and try again.<br>
><br>
> Content, title, and excerpt are empty.<br>
><br>
> I've been debugging the thing to death and still can't get any closer. I<br>
> have a feeling that it has something to do with how the struct datatypes are<br>
> being encoded in the XML-RPC portion. Here is a sample of my code:<br>
><br>
><br>
> $this->makeRequest(<br>
> 'wp.newComment',<br>
> array(<br>
> new xmlrpcval($blogId),<br>
> new xmlrpcval($this->username),<br>
> new xmlrpcval($this->password),<br>
> new xmlrpcval($postId),<br>
> xmlrpc_encode(array(<br>
> 'comment_parent'=>intval(0),<br>
> 'content'=>strval($comment->content),<br>
> 'author'=>strval($comment->author),<br>
> 'author_url'=>strval($comment->author_url),<br>
> 'author_email'=>strval($comment->author_email)<br>
> )),<br>
> ));<br>
><br>
> The structure containing the comment information ends up being encoded to<br>
> this:<br>
><br>
> <params><br>
> <param><br>
> <value><br>
> <struct><br>
> <member><br>
> <name>comment_parent</name><br>
> <value><br>
> <int>0</int><br>
><br>
> </value><br>
> </member><br>
> <member><br>
> <name>content</name><br>
> <value><br>
> <string>comment</string><br>
> </value><br>
> </member><br>
><br>
> <member><br>
> <name>author</name><br>
> <value><br>
> <string>Tim</string><br>
> </value><br>
> </member><br>
> <member><br>
> <name>author_url</name><br>
><br>
> <value><br>
> <string><a href="http://www.golen.net/blog" target="_blank">http://www.golen.net/blog</a></string><br>
> </value><br>
> </member><br>
> <member><br>
> <name>author_email</name><br>
> <value><br>
> <string><a href="mailto:tim@golen.net" target="_blank">tim@golen.net</a></string><br>
><br>
> </value><br>
> </member><br>
> </struct><br>
> </value><br>
> </param><br>
> </params><br>
><br>
><br>
> And all that is encoded the way they discuss it at<br>
> <a href="http://devzone.zend.com/article/1307" target="_blank">http://devzone.zend.com/article/1307</a>. I'll take a look at the IXR library<br>
> and see if that does any better of a job. I appreciate all of your help and<br>
> suggestions with this! Once I get the PHP library built, I think it would be<br>
> an invaluable resource to post on the Wordpress site somewhere.<br>
><br>
> Tim<br>
><br>
> On Tue, Jun 15, 2010 at 12:37 PM, Joseph Scott <<a href="mailto:joseph@josephscott.org" target="_blank">joseph@josephscott.org</a>>wrote:<br>
><br>
> > There are 2 different "levels" of libraries for the the WP XML-RPC<br>
> > APIs. First, lower level XML-RPC only APIs. These take care of all<br>
> > the XML-RPC work, but don't know anything about the specific methods<br>
> > that WordPress provides. For that layer I recommend the PHP IXR<br>
> > library, which is what WordPress uses.<br>
> ><br>
> > The next level up are libraries both take care of the XML-RPC details<br>
> > and know about the various methods that WP exposes. I've seen some<br>
> > Perl libraries that fit into this category, but I haven't seen much in<br>
> > the of PHP ones.<br>
> ><br>
> > On Tue, Jun 15, 2010 at 11:51 AM, Tim Golen <<a href="mailto:tim@golen.net" target="_blank">tim@golen.net</a>> wrote:<br>
> > > Is there already an existing PHP library for the Wordpress API? I'm still<br>
> > > running into problems and don't need to reinvent the wheel if it's<br>
> > already<br>
> > > been done. The MetaWeblog API mentions a PHP library, but it comes up<br>
> > with a<br>
> > > 404 error, and the MetaWeblog site hasn't been updated since 2003.<br>
> > > Errors like "Invalid Data: Please go back and try again." when trying to<br>
> > do<br>
> > > something rather simple like create a comment can get really frustrating.<br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > Joseph Scott<br>
> > <a href="mailto:joseph@josephscott.org" target="_blank">joseph@josephscott.org</a><br>
> > <a href="http://josephscott.org/" target="_blank">http://josephscott.org/</a><br>
> > _______________________________________________<br>
> > wp-xmlrpc mailing list<br>
> > <a href="mailto:wp-xmlrpc@lists.automattic.com" target="_blank">wp-xmlrpc@lists.automattic.com</a><br>
> > <a href="http://lists.automattic.com/mailman/listinfo/wp-xmlrpc" target="_blank">http://lists.automattic.com/mailman/listinfo/wp-xmlrpc</a><br>
> ><br>
</div>
</div></div></div>
<br>_______________________________________________<br>
wp-xmlrpc mailing list<br>
<a href="mailto:wp-xmlrpc@lists.automattic.com">wp-xmlrpc@lists.automattic.com</a><br>
<a href="http://lists.automattic.com/mailman/listinfo/wp-xmlrpc" target="_blank">http://lists.automattic.com/mailman/listinfo/wp-xmlrpc</a><br>
<br></blockquote></div><br></div>