Request user recenttracks from lastfm with codeigniter and xmlrpc

☆樱花仙子☆ 提交于 2020-01-03 05:07:12

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/4855873/request-user-recenttracks-from-lastfm-with-codeigniter-and-xmlrpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!