使用codeigniter和xmlrpc从lastfm请求用户latesttracks [英] Request user recenttracks from lastfm with codeigniter and xmlrpc

查看:180
本文介绍了使用codeigniter和xmlrpc从lastfm请求用户latesttracks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,怪人!
我试图用Codeigniter从last.fm获取一些信息。

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

我总是得到的唯一响应是:参数无效 - 缺少必需的参数



它尝试了一些与请求数组的变体,但它只是doenst工作的方式我处理... ...



如果有人可以帮助我,我会很高兴。



感谢Metalmatze

解决方案

您就近了。 $ 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.

这篇关于使用codeigniter和xmlrpc从lastfm请求用户latesttracks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆