【问题标题】:Sound Cloud ErrorSoundcloud 错误
【发布时间】:2012-07-10 10:11:43
【问题描述】:

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

有什么想法吗?

谢谢

【问题讨论】:

    标签: php audio soundcloud


    【解决方案1】:

    初始化new Services_Soundcloud时需要设置clientIDclientSecretredirectURI参数。

    您的代码应如下所示:

    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/

    【讨论】:

    • 答案已更新。看来您还需要设置第三个参数redirectURI。查看文档。
    • 还是不行。如果我注释掉 //$current_user = json_decode($client->get('me'));,则不会显示错误
    猜你喜欢
    • 2015-03-24
    • 2016-11-18
    • 1970-01-01
    • 2015-12-12
    • 1970-01-01
    • 2015-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多