【问题标题】:soundcloud api php add followersoundcloud api php 添加关注者
【发布时间】: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


【解决方案1】:

经过大量研究和反复试验,如果确定设置路径:

https://api.soundcloud.com/me/followings/#######?oauth_token=MY_TOKEN

似乎有效。我不知道这是否只是一种解决方法或 API 打算如何使用,但它是我可以让它工作的唯一方法,我假设 soundcloud 客户端对象正在使用命令自动发送令牌但它出现不是。

我还发现,如果它确实找到了匹配项(用户正在跟踪 id 号),那么它会返回一个 303 错误,api 指南甚至没有在他们的 http 错误代码中列出。

【讨论】:

    【解决方案2】:

    me 前面有一个斜线,它不能在那里。以下对我有用:

    $soundcloud->put('me/followings/#########','',array(CURLOPT_HTTPHEADER => array('Content-Type: application/xml')));
    

    【讨论】:

      猜你喜欢
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2011-02-12
      • 1970-01-01
      • 2012-07-20
      • 2019-07-11
      相关资源
      最近更新 更多