我成功解析了一些json
来自 的内容youtube api
,但每个请求我只能显示 50 个结果(由于 api 的限制),所以我将如何在我的脚本中实现Javascript
或Ajax
(你认为最好的)php
来对更多视频进行分页以显示观看者到达列表底部后的结果(例如,显示“再显示 50 个视频”的链接)
我是这种编程的新手,所以请帮忙
<?php
$id = urlencode($_GET['id']);
$url = "https://gdata.youtube.com/feeds/api/playlists/$id?alt=jsonc&v=2&start-index=1
&max-results=50";
$content = file_get_contents($url);
$json = json_decode($content, true);
echo "<div id=\"info\"><center><h1><b>{$json['data']['title']}</center></b></h1><br>{$json['data']['description']} there are {$json['data']['totalItems']} uploaded in this playlist.</center><p></div><div class=\"decoration\"></div>";
echo "<div id=\"center\">";
echo "<ul>";
$count = 0;
foreach ($json['data']['items'] as $items) {
++$count;
echo "<li style=\"width: 300px;min-height: auto;border: none;display: inline-block;margin: 5px;padding:10px;background-color: rgba(17,0,52,0.14);border-radius: 5px;\"><a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><font size=\"5\" style=\"font-weight:bold;\">{$items['video']['title']}</font></a><Br \>";
echo "<a href=\"video.php?plid={$json['data']['id']}&vidid={$items['video']['id']}\"><img style=\"width:300;height:auto;\" src=\"{$items['video']['thumbnail']['hqDefault']}\" title=\"{$items['video']['title']}\" id=\"ytThumb\"></img></a></li>";
}
echo "</ul>";
echo "</div>";
?>