php 如何使用 youtube api 从播放列表中获取所有视频?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13358290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:14:49  来源:igfitidea点击:

How get all videos from a playlist using youtube api?

phpxmlyoutubeyoutube-api

提问by crynaldo madrid

Now i am using this link

现在我正在使用这个链接

http://gdata.youtube.com/feeds/api/playlists/plalistID

to retrieve video from YouTube playlist. but the problem is only getting 25 video. but the playlist contains 100 videos. How get all video from playlist?

从 YouTube 播放列表中检索视频。但问题是只能获得 25 个视频。但播放列表包含 100 个视频。如何从播放列表中获取所有视频?

采纳答案by VolkerK

Youtube let's you fetch up to 50 entries per request.
The response contains some <link>elements. And if there are still more records to fetch one of it is of the form <link rel='next' ...e.g.

Youtube 让您可以为每个请求获取多达 50 个条目。
响应包含一些<link>元素。如果还有更多的记录来获取其中之一的形式,<link rel='next' ...例如

<link
  rel='next'
  type='application/atom+xml'
  href='https://gdata.youtube.com/feeds/api/playlists/plalistID?start-index=26&amp;max-results=25&amp;v=2'
/>

Search for this element and retrieve the document that the href attribute points to until the repsonse has no <link rel='next'element.

搜索此元素并检索 href 属性指向的文档,直到 repsonse 没有<link rel='next'元素为止。

回答by Salman A

YouTube API v3

YouTube API v3

You need to request the PlaylistItems > listfeed:

您需要请求PlaylistItems > 列表提要:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=PLVfin74Qx3tV8bgAhzbfDpnfPoGmJWAcn&key=YOUR_API_KEY

The JSON returned by the API will contain these properties:

API 返回的 JSON 将包含以下属性:

  • nextPageToken
  • prevPageToken
  • nextPageToken
  • prevPageToken

Pass one of these values in the pageTokenquery string parameter to retrieve the next or previous "page" in the result set:

pageToken查询字符串参数中传递这些值之一以检索结果集中的下一个或上一个“页面”:

https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=25&playlistId=PLVfin74Qx3tV8bgAhzbfDpnfPoGmJWAcn&pageToken=xxYYzz&key=YOUR_API_KEY

The JSON also contains pageInfo.resultsPerPageand pageInfo.totalResultsproperties.

JSON 还包含pageInfo.resultsPerPagepageInfo.totalResults属性。



YouTube API v2 answer is here.

YouTube API v2 答案在这里