Question

I'm trying to get some information from last.fm with Codeigniter.

$this->load->library("xmlrpc");
$this->xmlrpc->server("http://ws.audioscrobbler.com/2.0/", 80);
$this->xmlrpc->method("user.getrecenttracks");
$request = array("rj", "b25b959554ed76058ac220b7b2e0a026");
$this->xmlrpc->request($request);
if(!$this->xmlrpc->send_request())
{
    echo $this->xmlrpc->display_error();
}

The only response I always get is: Invalid parameters - Your request is missing a required parameter

It tried some variations with the request array, but it simply doesn't work the way I handle it...

Was it helpful?

Solution

You're close. $request should actually be written like this:

$request = array(
                 array(
                       array(
                             'user'=>'rj', 
                             'api_key'=>'b25b959554ed76058ac220b7b2e0a026'
                            ),
                       'struct'
                      )
                );

The actual request that CodeIgniter's XML-RPC class constructs will then look like this:

<?xml version="1.0"?>
<methodCall>
    <methodName>user.getrecenttracks</methodName>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>user</name>
                        <value>
                            <string>rj</string>
                        </value>
                    </member>
                    <member>
                        <name>api_key</name>
                        <value>
                            <string>b25b959554ed76058ac220b7b2e0a026</string>
                        </value>
                    </member>
                </struct>
            </value>
        </param>
    </params>
</methodCall>

You can see an example Last.fm XML-RPC request here. Note that you should "send your params as named arguments using a struct in the first param node." Keeping that in mind, the CodeIgniter docs state:

If you use data types other than strings, or if you have several different data types, you will place each parameter into its own array, with the data type in the second position.

Hope that helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top