api - Youtube 数据 API 版本 3 分页

标签 api youtube pagination

我知道 youtube 响应包含下一页和上一页标记,我们可以使用它们转到上一页和下一页。

例如:

https://www.googleapis.com/youtube/v3/search?&key={key}&part=snippet&maxResults=20&order=viewCount&q=abc&type=video&videoDuration=long&videoType=movie&pageToken=Cd323A

我的问题是如何导航到 第 n 个 特定搜索的页面?

请注意,有些人可能会认为这是不可能的。但我已经看到一些网站实现了这一点。

最佳答案

Youtube API 仅提供 NextPageTokenPreviousPageToken ,就是这样,抱歉:请参阅此处的文档:https://developers.google.com/youtube/v3/docs/videos/list

您仍然可以创建分页项,但必须通过多次调用 URL 并传递 NextPageToken 来实现它。如 pageToken在您每次请求中,并缓存结果。

顺便说一下,这里已经回答了这个问题(请参阅答案的第一点):youtube data api v3 php search pagination?

引用他们:

In particular your case where you need 50 pages per page and you are showing 3 pagination like (1,2,NEXT) then you need to fetch results two times. Both the results you will keep in cache so for page 1 and 2 results will be retrieved from cache. For next you make it sure that you are making query google again by sending nextPageToken.

Thus to show pagination 1-n and every page 50 results then you need to make n-1 queries to google api. But if you are showing 10 results per page then you cane make single query of 50 results using which you can show first 5 pages (1-5) with the help of retrieved results and at next you should again send next page token like above.

NOTE- Google youtube api provide 50 results max.

关于api - Youtube 数据 API 版本 3 分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25079501/

相关文章:

jquery - 在 ASP.NET MVC 3 下的 "Page-less"设计中使用 jQuery JSON 请求的 API 驱动设计有哪些缺点?

html - Youtube 视频的 JW 播放器不工作

javascript - Angular 分页

php - 需要使用 CI 分页技术的特定分页样式

ruby-on-rails - 在没有 will_paginate gem 的情况下在 Ruby 中实现分页

android - 将应用上传到 Playstore 后谷歌地图不显示

ios - 如何使用 Alamofire 使用以下参数进行 API 调用(Mashape)?

ruby - Grape 中的多个路由参数

javascript - YouTube 自动播放在 Chrome 中不起作用

javascript - 不使用 SWFObject 使嵌入的 YouTube 视频静音