我正在制作一个页面,您可以登录您的soundcloud并获得下载我的歌曲的权限,只要您在soundcloud上跟踪我。我有身份验证工作,但无法确定以下部分。我几乎复制并粘贴了soundcloud开发人员网站的示例,下面是类似的并遵循部分,而且它的接缝也没有按照预期的方式工作。尝试捕获显示我没有跟踪我的主帐户(我通过测试身份验证步骤获得了用户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和下面的/#被更改以保护我的信息。
发布于 2015-01-22 22:17:26
经过大量的研究和尝试,如果找出了设置路径的话:
https://api.soundcloud.com/me/followings/#######?oauth_token=MY_TOKEN似乎很管用。我不知道这是否只是一种解决办法,或者API是如何被使用的,但这是我能让它工作的唯一方法,我假设soundcloud客户端对象使用命令自动发送令牌,但它似乎没有。
我还发现,如果它确实找到了一个匹配(用户正在跟踪id号),那么它返回一个303错误,api指南甚至没有在他们的http错误代码中列出这个错误。
发布于 2017-09-27 21:30:38
在me前面有一个斜杠,它肯定不在那里。以下几点对我来说是可行的:
$soundcloud->put('me/followings/#########','',array(CURLOPT_HTTPHEADER => array('Content-Type: application/xml')));https://stackoverflow.com/questions/28016587
复制相似问题