我正在创建一个页面,您可以使用soundcloud登录,只要您在soundcloud上关注我,就可以下载我的歌曲。我有身份验证工作,但无法弄清楚以下部分。我几乎复制并粘贴了soundcloud开发者网站下的例子和跟随部分,它的接缝也没有按照它应该如何工作。 try catch使我看起来我没有关注我的主帐户(我从测试身份验证步骤获得了用户ID#),即使我在我的测试帐户上继续使用soundcloud并关注我的主帐户。这是我得到的错误:
Warning: Missing argument 2 for Services_Soundcloud::put(), called in /my_website/index.php on line 43 and defined in /my_website/Services/Soundcloud.php on line 636
Notice: Undefined variable: postData in /my_website/Services/Soundcloud.php on line 642
Fatal error: Uncaught exception 'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 404.' in /my_website/Services/Soundcloud.php:941
Stack trace:
#0 /my_website/Services/Soundcloud.php(645): Services_Soundcloud->_request('https://api.sou...', Array)
#1 /my_website/index.php(43): Services_Soundcloud->put('/me/followings/...')
#2 {main}
thrown in my_website/Services/Soundcloud.php on line 941
继承人运行的代码:
require_once 'Services/Soundcloud.php';
//session_destroy();
session_start();
$soundcloud = new Services_Soundcloud(client_id, secret_id, redirect_uri)
$authURL = $soundcloud->getAuthorizeUrl();
echo "<pre>";
if (!empty ($_SESSION['token'])){
$soundcloud->setAccessToken($_SESSION['token']);
} else if(!empty($_GET['code'])){
try{
$accessToken = $soundcloud->accessToken($_GET['code']);
$_SESSION['token'] = $accessToken['access_token'];
$soundcloud->setAccessToken($_SESSION['token']);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
} else {
echo "<a href='".$authURL."'><img border='0' alt='Connect with Soundcloud' src='connect.png'></a>";
}
if (!empty ($_SESSION['token'])){
// check the status of the relationship
echo $_SESSION['token'];
try {
$soundcloud->get('/me/followings/#######');
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
if ($e->getHttpCode() == '404')
print "You are not following user #######\nTrying to follow now\n";
$soundcloud->put('/me/followings/#######');
}
}
在获得这些命令之前,soundcloud上的示例是错误的还是我做错了什么?
另请注意,我的soundcloud对象init和followings / #####已更改为保护我的信息。
答案 0 :(得分:0)
经过大量的研究和试验和错误后,如果弄清楚将路径设置为:
https://api.soundcloud.com/me/followings/#######?oauth_token=MY_TOKEN
似乎有效。我不知道这只是一种解决方法或者API是如何使用的,但它是我可以使它工作的唯一方法,我假设soundcloud客户端对象是使用命令自动发送令牌但它出现不
我还发现,如果找到匹配项(用户正在跟踪id号),则会返回303错误,api指南甚至没有在其http错误代码中列出。
答案 1 :(得分:0)
me
前面有一个斜线,它必须不在那里。以下适用于我:
$soundcloud->put('me/followings/#########','',array(CURLOPT_HTTPHEADER => array('Content-Type: application/xml')));