[wp-xmlrpc] PHP Library

Tim Golen tim at golen.net
Tue Jun 15 20:01:49 UTC 2010


Yay! Looks like it's working finally. I at least got a category created. Now
to move to the others. Thanks again for the help.

For the record, I was right about the struct datatype, just use an array
with key=>val pairs like this:

array(
'name'=>$category->name
)

On Tue, Jun 15, 2010 at 1:39 PM, eric at eamann.com <eric at eamann.com> wrote:

>  Tim,
>
>
>
> I haven't worked specifically with struct datatypes (in reality, most of
> the time I just build my own procedure on the server I'm working with) ...
> but the documentation says you can use them.
>
>
>
> Here's the full documentation for the IXR library if you want to take a
> crack at it: http://scripts.incutio.com/xmlrpc/manual.php  Just be sure to
> post your solution here so we can all learn from you :-)
>
>
>
> ~Eric
>
>
>  On June 15, 2010 at 7:20 PM Tim Golen <tim at golen.net> wrote:
>
> > 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?
> >
> > Tim
> >
> > On Tue, Jun 15, 2010 at 1:06 PM, eric at eamann.com <eric at eamann.com>
> wrote:
> >
> > >  OK, now I understand what you're doing.
> > >
> > >
> > >
> > > 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.
> > >
> > >
> > >
> > > Here's a simple example:
> > >
> > >
> > >
> > > include_once(ABSPATH . WPINC . '/class-IXR.php');
> > >
> > >
> > >
> > > $client = new IXR_Client('destinantion_url');
> > >
> > >
> > >
> > > $client->query('procedure.name', 'arg1', 'arg2', 'arg3', ...);
> > >
> > >
> > >
> > > $response = $client->getResponse();
> > >
> > >
> > >
> > > 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.
> > >
> > >
> > >
> > >
> > >  On June 15, 2010 at 6:51 PM Tim Golen <tim at golen.net> wrote:
> > >
> > > > Hi Joseph,
> > > >
> > > > Right on, that's exactly what I needed to know.
> > > >
> > > > I've been using http://devzone.zend.com/article/1307 for the XML-RPC
> > > (lower
> > > > level) API, and then building my own PHP library on top of that (with
> the
> > > > Wordpress functions). I'll go and check out the IXR library to see if
> > > that
> > > > helps.
> > > >
> > > > All of the calls that I am making that pull data from Wordpress are
> > > working
> > > > fine. It's just when trying to create data (wp.newComment,
> > > wp.newCategory,
> > > > metaWeblog.newPost) they are all giving me similar data errors:
> > > >
> > > > Sorry, the new category failed.
> > > >
> > > > Invalid Data: Please go back and try again.
> > > >
> > > > Content, title, and excerpt are empty.
> > > >
> > > > I've been debugging the thing to death and still can't get any
> closer. I
> > > > have a feeling that it has something to do with how the struct
> datatypes
> > > are
> > > > being encoded in the XML-RPC portion. Here is a sample of my code:
> > > >
> > > >
> > > > $this->makeRequest(
> > > > 'wp.newComment',
> > > > array(
> > > > new xmlrpcval($blogId),
> > > > new xmlrpcval($this->username),
> > > > new xmlrpcval($this->password),
> > > > new xmlrpcval($postId),
> > > > xmlrpc_encode(array(
> > > > 'comment_parent'=>intval(0),
> > > > 'content'=>strval($comment->content),
> > > > 'author'=>strval($comment->author),
> > > > 'author_url'=>strval($comment->author_url),
> > > > 'author_email'=>strval($comment->author_email)
> > > > )),
> > > > ));
> > > >
> > > > The structure containing the comment information ends up being
> encoded to
> > > > this:
> > > >
> > > > <params>
> > > > <param>
> > > >  <value>
> > > >   <struct>
> > > >    <member>
> > > >     <name>comment_parent</name>
> > > >     <value>
> > > >      <int>0</int>
> > > >
> > > >     </value>
> > > >    </member>
> > > >    <member>
> > > >     <name>content</name>
> > > >     <value>
> > > >      <string>comment</string>
> > > >     </value>
> > > >    </member>
> > > >
> > > >    <member>
> > > >     <name>author</name>
> > > >     <value>
> > > >      <string>Tim</string>
> > > >     </value>
> > > >    </member>
> > > >    <member>
> > > >     <name>author_url</name>
> > > >
> > > >     <value>
> > > >      <string>http://www.golen.net/blog</string>
> > > >     </value>
> > > >    </member>
> > > >    <member>
> > > >     <name>author_email</name>
> > > >     <value>
> > > >      <string>tim at golen.net</string>
> > > >
> > > >     </value>
> > > >    </member>
> > > >   </struct>
> > > >  </value>
> > > > </param>
> > > > </params>
> > > >
> > > >
> > > > And all that is encoded the way they discuss it at
> > > > http://devzone.zend.com/article/1307. I'll take a look at the IXR
> > > library
> > > > and see if that does any better of a job. I appreciate all of your
> help
> > > and
> > > > suggestions with this! Once I get the PHP library built, I think it
> would
> > > be
> > > > an invaluable resource to post on the Wordpress site somewhere.
> > > >
> > > > Tim
> > > >
> > > > On Tue, Jun 15, 2010 at 12:37 PM, Joseph Scott <
> joseph at josephscott.org
> > > >wrote:
> > > >
> > > > > There are 2 different "levels" of libraries for the the WP XML-RPC
> > > > > APIs.  First, lower level XML-RPC only APIs.  These take care of
> all
> > > > > the XML-RPC work, but don't know anything about the specific
> methods
> > > > > that WordPress provides.  For that layer I recommend the PHP IXR
> > > > > library, which is what WordPress uses.
> > > > >
> > > > > The next level up are libraries both take care of the XML-RPC
> details
> > > > > and know about the various methods that WP exposes.  I've seen some
> > > > > Perl libraries that fit into this category, but I haven't seen much
> in
> > > > > the of PHP ones.
> > > > >
> > > > > On Tue, Jun 15, 2010 at 11:51 AM, Tim Golen <tim at golen.net> wrote:
> > > > > > Is there already an existing PHP library for the Wordpress API?
> I'm
> > > still
> > > > > > running into problems and don't need to reinvent the wheel if
> it's
> > > > > already
> > > > > > been done. The MetaWeblog API mentions a PHP library, but it
> comes up
> > > > > with a
> > > > > > 404 error, and the MetaWeblog site hasn't been updated since
> 2003.
> > > > > > Errors like "Invalid Data: Please go back and try again." when
> trying
> > > to
> > > > > do
> > > > > > something rather simple like create a comment can get really
> > > frustrating.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Joseph Scott
> > > > > joseph at josephscott.org
> > > > > http://josephscott.org/
> > > > > _______________________________________________
> > > > > wp-xmlrpc mailing list
> > > > > wp-xmlrpc at lists.automattic.com
> > > > > http://lists.automattic.com/mailman/listinfo/wp-xmlrpc
> > > > >
> > >
> > > _______________________________________________
> > > wp-xmlrpc mailing list
> > > wp-xmlrpc at lists.automattic.com
> > > http://lists.automattic.com/mailman/listinfo/wp-xmlrpc
> > >
> > >
>
> _______________________________________________
> wp-xmlrpc mailing list
> wp-xmlrpc at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-xmlrpc
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.automattic.com/pipermail/wp-xmlrpc/attachments/20100615/01f26333/attachment.htm>


More information about the wp-xmlrpc mailing list