声音云错误

时间:2012-07-10 10:11:43

标签: php audio soundcloud

这是我的redirect.php,我总是得到 'HTTP错误500(内部服务器错误):服务器尝试完成请求时遇到意外情况。 “

php代码:

require_once 'Services/Soundcloud.php';

// create client object with app credentials 
$client = new Services_Soundcloud('xxxxxxxxxxxxxxxxxxxxxxx');
$client->setAccessToken($_GET['code']);

// make an authenticated call
$current_user = json_decode($client->get('me'));
print $current_user->username;

有什么想法吗?

感谢

1 个答案:

答案 0 :(得分:2)

初始化clientID时,您需要设置clientSecretredirectURInew Services_Soundcloud个参数。

您的代码应如下所示:

index.php
<?php

// create client object with app credentials
include('Services/Soundcloud.php');
$client = new Services_Soundcloud('....', '....', 'http://my.redirect.com/url.php');
$authorizeUrl = $client->getAuthorizeUrl();

?>

<a href="<?php echo $authorizeUrl; ?>">Connect with SoundCloud</a>

重定向网址:

<?php

require_once('Services/Soundcloud.php');

// create client object with app credentials
$client = new Services_Soundcloud('.....', '.....', 'http://my.redirect.com/url.php');

try {
    $accessToken = $client->accessToken($_GET['code']);
    try {
        $me = json_decode($client->get('me'), true);
        var_dump($me);
    } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
        var_dump($e->getMessage());
        exit();
    }

} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
    var_dump($e->getMessage());
    exit();
}

?>

您可以从developers page

获取clientIdclientSecret

您还可以查看documentation以获取PHP,Python,Ruby和JS中的正确示例

您可以在此链接上查看上面的代码:
soundcloud.itnews-bg.com/