gpt4 book ai didi

php - 无需身份验证即可拉取 Soundcloud 轨道列表

转载 作者:搜寻专家 更新时间:2023-10-31 20:44:41 25 4
gpt4 key购买 nike

我想拉取某个用户的轨道列表并显示它。现在我正在做这件事,但我总是需要连接(通过按链接)是否有一种方法可以消除此步骤或始终进行身份验证的方法。我在 soundcloud api 上重新搜索了这个但没有成功,我不明白为什么在访问公共(public)数据时需要身份验证。

<?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>';
}
?>

最佳答案

您可以像这样创建一个轨道列表:

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,但我的想法是向以下网址):

$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>';
}

你真的不需要在这里进行身份验证。

关于php - 无需身份验证即可拉取 Soundcloud 轨道列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14687968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com