实现:分页
以下示例展示了如何检索 YouTube Data API (v3) 查询的其他结果集。
该 API 使用 maxResults
参数来指明 API 响应中应包含的项数。API 的几乎所有 list
方法(videos.list
、playlists.list
等)都支持该参数。
如果查询有其他结果,则 API 响应将包含 nextPageToken
属性和/或 prevPageToken
属性。然后,您可以使用这些媒体资源的值来设置 pageToken
参数,以检索下一页结果。
例如,以下查询会检索与搜索查询“skateboarding dog”(滑板狗)匹配的观看次数最多的前 10 个视频的搜索结果:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&q=skateboarding+dog
&type=video
API 响应包含查询的前 10 个匹配项,以及一个 nextPageToken
属性,可用于检索接下来的 10 个结果:
以下查询会检索查询的下 10 条结果:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?
part=snippet
&maxResults=10
&order=viewCount
&pageToken=CAoQAA
&q=skateboarding+dog
&type=video
注意:您可能需要更新 pageToken
参数的值,才能在 API Explorer 中完成此请求。执行用于检索前 10 个结果的查询,以获取正确的 pageToken
参数值。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-23。
[null,null,["最后更新时间 (UTC):2024-11-23。"],[[["The YouTube Data API (v3) uses the `maxResults` parameter to determine the number of items returned in a query response."],["API `list` methods, such as `videos.list` and `playlists.list`, support the `maxResults` parameter for pagination."],["If more results are available, the API response includes `nextPageToken` and/or `prevPageToken` properties."],["These token values can be used to set the `pageToken` parameter to retrieve additional result pages."],["The initial request fetches the first page of results, and subsequent requests use the `pageToken` from the previous response to get the next page of results."]]],["The YouTube Data API (v3) uses `maxResults` to specify the number of items in a response. `list` methods support this, and responses with additional results include `nextPageToken` or `prevPageToken`. These tokens, used with the `pageToken` parameter, retrieve further result sets. For instance, a query can get 10 most viewed videos, and a `nextPageToken` in the response allows fetching the next 10 by adding this value in the `pageToken` parameter.\n"]]