【问题标题】:Youtube video list paginationYoutube 视频列表分页
【发布时间】:2018-11-25 17:07:38
【问题描述】:

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

下面是我的代码:

          $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 的信息,但我不知道如何获取它的价值以使其正常工作。

【问题讨论】:

    标签: php youtube-data-api


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-10-26
      • 2014-02-09
      • 2018-06-11
      • 1970-01-01
      • 2021-12-19
      • 2017-08-25
      • 2012-10-24
      • 2012-12-06
      • 2019-04-04
      相关资源
      最近更新 更多