我想拉出某个用户跟踪列表并显示它。现在我正在做这个,但我总是需要连接(通过按下链接)是否有一种方法可以消除这一步或者总是经过身份验证的方式。我在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>';
}
?>
答案 0 :(得分:3)
你可以像这样创建一个音轨列表:
echo '<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/users/857348"></iframe>';
否则,如果您需要检索轨道列表并为每个轨道创建窗口小部件(不是真的推荐),您可以使用它(注意我不是在编写很多PHP,但想法是向HTTP发出HTTP GET以下网址):
$tracks_json = file_get_contents('http://api.soundcloud.com/users/857348/tracks.json?client_id=YOUR_CLIENT_ID');
$tracks = json_decode($tracks_json);
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>';
}
你真的不需要在这里验证。