我正在制作一个页面,您可以在其中使用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
这是 IM 运行的代码:
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 和 follows/##### 已更改以保护我的信息。
经过大量的研究和反复试验,如果发现设置路径:
https://api.soundcloud.com/me/followings/#######?oauth_token=MY_TOKEN
似乎有效。我不知道这是否只是一种解决方法,或者 API 的用途,但这是我让它工作的唯一方法,我假设 soundcloud 客户端对象使用命令自动发送令牌,但似乎不是。
我还发现,如果它确实找到匹配项(用户正在关注 ID 号),那么它会返回一个 303 错误,API 指南甚至没有在其 http 错误代码中列出该错误。
你在me
前面有一个斜杠,不能在那里。以下内容对我有用:
$soundcloud->put('me/followings/#########','',array(CURLOPT_HTTPHEADER => array('Content-Type: application/xml')));