且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用codeigniter和xmlrpc从lastfm请求用户latesttracks

更新时间:2022-10-16 08:56:33

您就近了。 $ request 应该实际写成这样:

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

);

CodeIgniter的XML-RPC类构造的实际请求将如下所示:

 <?xml version =1.0?> 
< methodCall>
< methodName> user.getrecenttracks< / methodName>
< params>
< param>
< value>
< struct>
< 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>

您可以看到一个示例Last.fm XML-RPC请求此处。请注意,您应该在第一个param节点中使用struct来将您的参数发送为命名参数。记住这一点, CodeIgniter文档状态:


如果你使用除
字符串以外的数据类型,或者你有几个
不同的数据类型,你将
每个参数放入它的自己的数组,
,数据类型在第二个
位置。


希望有帮助。 >

Hey geeks! 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 doenst work the way I handle it...

I would be happy if someone could help me out.

Thanks Metalmatze

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.