Codeigniter中的SoundCloud API 401错误

时间:2015-01-02 19:24:17

标签: codeigniter soundcloud

我正在尝试让Soundcloud返回一个曲目ID,但无法让它工作。这里的文档(PHP选项卡):https://developers.soundcloud.com/docs/api/guide#errors

我已经从soundcloud中检查了我的凭据,我将其添加为args。

我的控制器中的功能:

function formprocessor()     {

    require_once (APPPATH.'third_party/Services/Soundcloud.php');

    // create a client object with your app credentials
    $client = new Services_Soundcloud('my client id', 'my client secret', 'http://127.0.0.1:8888/index.php/welcome/');


    try {
        $me = json_decode($client->get('me'), true);
    }
    catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
        exit($e->getMessage());
    }
}

什么会导致失败?我一直在拿401 以下是对API的引用:https://developers.soundcloud.com/docs/api/reference

1 个答案:

答案 0 :(得分:0)

您需要通过将用户(即使那样)发送给" authorizeurl"来验证身份:

$authURL = $client->getAuthorizeUrl();

然后使用以下命令设置访问令牌:

$accessToken = $client->accessToken($_GET['code']);
$client->setAccessToken($_SESSION['token']);   //if you saved token in a session

然后你应该至少能够#34;得到我"这部分对我有用但是我现在无法访问/ me / tracks /或/ me / followings /等内容。