youtube - 访问YouTube用户上传供稿中超过start_index = 1000的项目

标签 youtube youtube-api gdata

我目前正在尝试从YouTube用户上传供稿中提取有关视频的数据。此供稿包含特定用户上传的所有视频,并且可以通过以下请求从API访问该供稿:

http://gdata.youtube.com/feeds/api/users/USERNAME/uploads

其中USERNAME是拥有Feed的YouTube用户的名称。

但是,尝试访问超过1000个视频的供稿时遇到了问题。由于对API的每个请求都可以返回50个项目,因此,我使用max_length和start_index遍历Feed,如下所示:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?start-index=1&max-results=50&orderby=published
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?start-index=51&max-results=50&orderby=published

依此类推,在每次调用时将start_index增加50。这可以完美地工作到:
http://gdata.youtube.com/feeds/api/users/USERNAME/uploads?start-index=1001&max-results=50&orderby=published

这时,我收到一条400错误消息,通知我“您不能要求商品1000以外的其他商品”。这让我感到困惑,因为我以为查询只会返回50个视频:按照最近发布的顺序显示1001-1051。浏览了documentation之后,我发现了这一点:

Limits on result counts and accessible results

...

For any given query, you will not be able to retrieve more than 1,000 results even if there are more than that. The API will return an error if you try to retrieve greater than 1,000 results. Thus, the API will return an error if you set the start-index query parameter to a value of 1001 or greater. It will also return an error if the sum of the start-index and max-results parameters is greater than 1,001.

For example, if you set the start-index parameter value to 1000, then you must set the max-results parameter value to 1, and if you set the start-index parameter value to 980, then you must set the max-results parameter value to 21 or less.



我不知道如何以一致的方式访问普通用户最近上传的第1001个视频以及以后的视频,因为它们不能仅使用max-results和start-index进行索引。有人对如何避免此问题有任何有用的建议吗?我希望我已经清楚地概述了困难!

最佳答案

支持来获取给定帐户的所有视频,但是您需要确保对上传Feed的请求针对的是后端数据库,而不是搜索索引。因为您在请求网址中包含orderby=published,所以您违反了搜索索引。搜索索引供稿最多只能有1000个条目。

摆脱orderby=published,您将获得所需的数据。无论如何,上传Feed的默认顺序是按时间倒序排列。

这是一个特别容易犯的错误,我们在博客上提供了更详细的解释:

http://apiblog.youtube.com/2012/03/keeping-things-fresh.html

令人高兴的是,这在API版本3中将不再是问题。

关于youtube - 访问YouTube用户上传供稿中超过start_index = 1000的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12708333/

相关文章:

python - 如何从根集合(文件夹)中删除资源(Google Docs 文档)

javascript - 如何获得Youtube直播位置?

gdata-api - 如何通过我自己的应用程序更新谷歌应用程序标准版用户的个人资料,即使用API

video - 如何使视频(缩略图)在SERP中显示,并带有指向您网站而非YouTube的链接

youtube - Google Play网络视频播放器API

youtube - 检查 YouTube 电影是否已重新索引

javascript - 如何使用 Angularjs 从 url 显示 youtube 缩略图

r - read.xls-读取长度可变的工作表列表及其名称

ios - iPhone : How to play a YouTube video in a certain view (instead of fullscreen)

jquery - 使用jQuery从HTML生成YouTube缩略图