我正在为SoundCloud开发一个应用程序,它是用PHP编写的,我使用库。
成功实例化Services_Soundcloud实例之后,我可以执行如下调用:
echo $soundcloud->get('me');
echo $soudcloud->get('users/12345678');然而,以下呼吁不起作用:
echo $soundcloud->get('resolve', array('url' => 'https://soundcloud.com/webfordreams'));我得到的错误是:
Services_Soundcloud_Invalid_Http_Response_Code_Exception:请求的URL使用HTTP 302进行响应。在Services_Soundcloud->_request()中(./php-soundcloud/Services/SoundCloud.php第933行)。
经过几个小时的调试,我决定寻求帮助,因为我真的不明白我做错了什么。
有人能帮我,告诉我如何得到正确的回应吗?
发布于 2013-06-21 06:51:45
根据api接口,您得到的“HTTP1.1 302”响应是适当的响应。如果检查完整的php异常,就会在响应正文中得到如下结果:
[httpBody:protected] => {"status":"302 -Found","location":"https://api.soundcloud.com/users/25071103"}为了允许CURL遵循重定向,您需要在调用soundcloud的get()函数时传递CURLOPT_FOLLOWLOCATION选项。
$result = $scloud->get('resolve', array('url' => 'https://soundcloud.com/webfordreams'), array(CURLOPT_FOLLOWLOCATION => TRUE ));不过,我对语法不太确定,但您最终想要得到的是Soundcloud的_request()函数中的如下内容:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);希望在这方面有更多经验的人会来给您提供适当的语法,而不是您必须修改SoundCloud SDK本身。
发布于 2013-11-06 21:31:25
从Francis.G的意思来看,您要寻找的语法是:
$soundcloud->get('resolve', array('url' => 'https://soundcloud.com/webfordreams'), array(CURLOPT_FOLLOWLOCATION => true);唯一的更改是作为第三个参数传递给get()函数的curl数组的定义。
https://stackoverflow.com/questions/14364705
复制相似问题