YouTube数据API版本3分页 [英] Youtube data API version 3 pagination
问题描述
我了解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仅提供NextPageToken
和PreviousPageToken
,就是这样,很抱歉:请参见此处的文档:
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.
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屋!