我知道 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 仅提供 NextPageToken
和 PreviousPageToken
,就是这样,抱歉:请参阅此处的文档: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/