【发布时间】:2015-01-19 00:59:13
【问题描述】:
我正在创建一个页面,您可以在其中使用您的 soundcloud 登录并获得下载我的歌曲的权限,只要您在 soundcloud 上关注我。我有身份验证工作,但无法弄清楚以下部分。我几乎从 soundcloud 开发者网站的 like 和 follow 部分复制并粘贴了这些示例,它接缝都没有按预期工作。即使我继续使用 soundcloud,在我的测试帐户上并关注我的主帐户,try catch 也使我似乎没有关注我的主帐户(我从测试身份验证步骤中获得了用户 id#)。这是我得到的错误:
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 和 follows/##### 已更改以保护我的信息。
【问题讨论】:
-
您应该在 soundcloud 中检查您的 postData 变量,您的 put 命令有问题。顺便提一句。我正在积极维护一个更加面向对象的库来使用 soundcloud 你试过了吗? github.com/njasm/soundcloud
-
很抱歉直到我找到答案才看到这个......并且有两个帐户。当我最终遇到另一个问题时,我一定会记住你的图书馆。谢谢!
-
没问题的朋友,祝你好运!
标签: php api soundcloud