我想提取某个用户跟踪列表并显示它。现在我正在执行此操作,但我总是需要连接(通过按下链接)是否有一种方法可以消除此步骤或始终进行身份验证。我已经在 soundcloud api 上重新搜索了这个但没有成功,我不明白为什么在访问公共数据时需要身份验证。
<?php
session_start();
//session_destroy();
require 'Soundcloud.php';
$soundcloud = new Services_Soundcloud('MY_CLIENT_ID', 'MY_SECRET', 'http://www.ericmlt.com/MarcKane/soundcloud/');
$soundcloud->setDevelopment(FALSE);
$authURL = $soundcloud->getAuthorizeUrl();
echo "<a href='$authURL'>Connect to Soundcloud</a>";
//Attempt to get token from Session first
//Set the token otherwise..
try {
$accessToken = $soundcloud->accessToken($_GET['code']);
if(!isset($_SESSION['token'])){
$_SESSION['token'] = $accessToken['access_token'] ;
} else {
$soundcloud->setAccessToken($_SESSION['token']);
}
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
try {
$tracks = json_decode($soundcloud->get('tracks', array('user_id' => '857348')), TRUE);
} catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) {
exit($e->getMessage());
}
foreach ($tracks as $track){
$trackID = $track['id'];
echo '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F'.$trackID.'"></iframe>';
}
?>