Youtube 数据 API 版本 3 分页 [英] Youtube data API version 3 pagination

查看:51
本文介绍了Youtube 数据 API 版本 3 分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I understand that youtube response contains the next and previous page tokens and we can use those to go to previous and next pages.

例如:

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页?

My question is how can I navigate to nth page of particular search?

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

Please note that some people may see this is impossible. But I have seen some site implemented this.

推荐答案

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

Youtube API only provides NextPageToken and PreviousPageToken, that's it, sorry: see documentation here: https://developers.google.com/youtube/v3/docs/videos/list

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

You can still make a pagination item but you will have to implement it by calling multiple times the URL, passing the NextPageToken as pageToken in your requestion every time, and caching results.

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

By the way, this question is already answered here (see the 1st point of the answer): youtube data api v3 php search pagination?

引用它们:

特别是在您需要每页 50 页的情况下显示 3 个分页,如 (1,2,NEXT) 然后你需要获取结果两次.您将保留在缓存中的两个结果,以便用于第 1 页和第 2 页结果将从缓存中检索.接下来你要确保您正在通过发送 nextPageToken 再次查询 google.

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.

因此要显示分页 1-n 和每页 50 结果,那么您需要对 google api 进行 n-1 次查询.但是如果你每显示 10 个结果页面然后您可以对 50 个结果进行单个查询,您可以使用它在检索结果的帮助下显示前 5 页 (1-5) 并在接下来你应该再次像上面一样发送下一页令牌.

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.

注意 - Google youtube api 最多提供 50 个结果.

NOTE- Google youtube api provide 50 results max.

这篇关于Youtube 数据 API 版本 3 分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆