2012-07-10 59 views
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; 

任何想法?

感謝

回答

2

你需要初始化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> 

而且重定向URL:

<?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/

+0

我嘗試過,但它不工作 – gigir 2012-07-10 14:18:34

+0

回答更新。看來你還需要設置第三個參數'redirectURI'。檢出文件。 – tftd 2012-07-10 15:06:56

+0

仍然不起作用。如果我註釋掉// $ current_user = json_decode($ client-> get('me'));,錯誤將不會顯示 – gigir 2012-07-10 23:53:17