优酷视频列表分页



我遇到了创建分页电影列表的问题。

下面是我的代码:

$API_key    = 'my_api_key';
$channelID  = 'channel_id';
$maxResults =  15;
$videoList = json_decode(file_get_contents('https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId='.$channelID.'&maxResults='.$maxResults.'&key='.$API_key.''));
foreach($videoList->items as $item){
if(isset($item->id->videoId)){
echo '<div class="youtube-video col-xl-4">
<iframe width="100%" height="100%" src="https://www.youtube.com/embed/'.$item->id->videoId.'" frameborder="0" allowfullscreen></iframe>
<h3>'. $item->snippet->title .'</h3>
</div>';
}
}

我错过了什么,接下来我应该做什么?我正在阅读有关pageToken的信息,但我不知道如何获得它的价值以使其正常工作。

当您在访问 YouTube 数据 API v3 端点时返回第一个结果时,$videoList可能有一个条目nextPageToken。如果是这样,则可通过$videoList["nextPageToken"]访问nextPageToken值。然后,要检索与您的请求关联的下一页数据,请添加到您的 URL&pageToken={NEXT_PAGE_TOKEN}其中{NEXT_PAGE_TOKEN}是与您刚刚在上一个请求中获得的条目nextPageToken关联的值。

最新更新