如何从 Youtube API(搜索 API)响应中获取所有结果 [英] How can get all results from Youtube API (search API) response

查看:51
本文介绍了如何从 Youtube API(搜索 API)响应中获取所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜欢标题.我做这样的请求:

Like the title. I do a request like this :

https://www.googleapis.com/youtube/v3/search?key=AIzaSyDuxczhyyvHWfxKuF3ygW9p0GWmKlvWLYc&part=id,snippet&publishedAfter=2014-12-09T00:00:00Z&publishedBefore=2014-12-11T00:00:00Z&videoCategoryId=GCSG93LXRvICYgRElZ&type=video&maxResults=50&pageToken=

总结果是 1000000.但我最多只能得到 500 个结果(10 页,50 个结果/页).在第 10 页,我没有看到 nextPageToken 属性可以转到下一页.???我不知道为什么.我怎样才能得到所有的结果.

Total result is 1000000. But I just can get 500 results maximum (10 page, 50 results/page). At 10th page, I don't see nextPageToken property to go to the next page. ??? I don't know why. How can I get all of result.

推荐答案

YouTube 强加了大约 500 的软限制.没有直接的方法可以通过 API 获得更多.

YouTube imposes a soft limit of about 500. There is no direct way to get more than that through the API.

完整详情:https://code.google.com/p/gdata-issues/issues/detail?id=4282

相关摘录:

如果搜索结果的质量严重下降(重复等),我们无法通过 API 为任意 YouTube 查询提供超过 500 个搜索结果.

"We can't provide more than ~500 search results for any arbitrary YouTube query via the API without the quality of the search results severely degrading (duplicates, etc.).

v1/v2 GData API 于 11 月更新,将返回的搜索结果数量限制为 500.如果您指定的起始索引为 500 或更多,您将不会返回任何结果.

The v1/v2 GData API was updated back in November to limit the number of search results returned to 500. If you specify a start-index of 500 or more, you won't get back any results.

这应该也适用于 v3 API(它使用不同的结果分页方法)但显然没有被推出,因此在 v3 中仍然可以检索多达 1000 个搜索结果——其中最后 500 个通常质量较差.

This was supposed to have also gone into effect for the v3 API (which uses a different method of paging through results) but it apparently was not pushed out, so it is still possible to retrieve up to 1000 search results in v3—the last 500 of which are usually of bad quality.

将 v3 限制为 500 个搜索结果的更改将在不久的将来推出.达到 500 个结果后,将不再返回 nextPageTokens.

The change to limit v3 to 500 search results will be pushed out sometime in the near future. There will no longer be nextPageTokens returned once you hit 500 results.

我知道在所有这些情况下返回的 totalResults 远高于 500,但这与说我们可以有效地返回所有 X 百万个可能的结果不同.它是对与查询匹配的视频集总大小的估计,通常不是很有用."

I understand that the totalResults that are returned is much higher than 500 in all of these cases, but that is not the same thing as saying that we can effectively return all X million possible results. It's meant as an estimate of the total size of the set of videos that match a query and normally isn't very useful."

更新 - 如何绕过 500 个结果的最大软限制

使用过滤器publishedAfter"和publishedBefore"按天/周/月将查询分解为查询循环,直到不再返回结果.每个定期查询应返回少于 500 个结果,但您会得到所有结果.

Use the filters 'publishedAfter' and 'publishedBefore' to break up your query into loops of queries by day/week/month until no more results are returned. Each periodic query should return less than 500 results each, but you'll get them all.

这篇关于如何从 Youtube API(搜索 API)响应中获取所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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