1

这是我的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;

任何想法?

谢谢

4

1 回答 1

2

初始化时需要设置clientID,clientSecret和参数。redirectURInew 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();
}

?>

您可以从开发人员页面clientId获取andclientSecret

您还可以查看文档以获取 PHP、Python、Ruby 和 JS 中的正确示例

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

于 2012-07-10T10:31:40.347 回答