如何使用 YouTube API 获取随机的 YouTube 视频? [英] How do I get a random YouTube video with the YouTube API?

查看:71
本文介绍了如何使用 YouTube API 获取随机的 YouTube 视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种获取完全随机 YouTube 视频的方法.没有限制.

I need a way of getting a completely random YouTube video. No restriction.

如何使用 YouTube API?

How can I do with with the YouTube API?

** 编辑 * 按要求确定,这是我到目前为止所尝试的:

** edit * OK as requested here is what i tried so far:

1 - 浏览了 youtube 开发网站上的 api 和示例.http://www.youtube.com/dev/ 没有找到正确的 api 或在那里做的方法.

1 - went through the api and examples at youtube dev site. http://www.youtube.com/dev/ no luck finding the correct api or a way of doing it there.

2 - 当然是谷歌搜索;)得到了 http://randomyoutubevideo.net/ 但他们只提供来自 THEM 的 api 用于在我和 youtube 之间.<这给了我希望,这实际上是可能的.

2 - google search of course ;) got http://randomyoutubevideo.net/ but they only offer an api from THEM to use in between me and youtube. < this gives me hope that it IS actually possible to do this.

3 - 甚至查看了 youtube 应用程序库 http://youtube-gallery.appspot.com/ 看看是否有人正在做.以及如何.

3 - even checked the youtube app gallery http://youtube-gallery.appspot.com/ to see if anyone is doing it. and HOW.

我还会在 youtube 讨论页面上提问.也许那里的人可以提供帮助.

what i will also do is ask on the youtube discussion pages. perhaps someone there can help.

推荐答案

似乎没有办法做到这一点,但是有一些方法可以近似您正在寻找的内容.请参阅此处了解想法.

There appears to be no way to do this, however there are ways to approximate what you're looking for. See here for ideas.

这些页面的基本想法是使用最新的上传提要(如果您不关心上传内容的时间),或者只是获取所有 youtube 视频的转储并从中随机选择一个 URL.

The basic ideas from those pages are to use the most recent uploads feed (if you don't care about when something was uploaded) or simply get a dump of ALL youtube videos and randomly select a URL from those.

在第一个链接中引用 youtube API 的人:

To quote the youtube API guy in first link:

正如其他人所提到的,我们会进行任何数据转储等可用的.您与 YouTube 的所有互动都需要通过标准 API.

As others have mentioned, we make any data dumps or the like available. All your interaction with YouTube needs to be done via the standard API.

我不能说我有足够的统计学背景建议您如何检索真正随机的视频样本.我做认为通过尝试生成 11 个字符来实现它不过,YouTube 视频 ID 可能是错误的方法——有您会遇到太多不存在的视频ID,并且我不认为 API 的最佳用途是发出将X% 的时间返回 HTTP 404 响应.

I can't say that I have enough of a background in statistics to suggest how you could retrieve a truly random sample of videos. I do think that going about it by attempting to generate 11 character YouTube video ids is probably the wrong approach, though—there are just too many non-existent video ids that you'll bump up against, and I don't think the best use of the API is to make requests that will return HTTP 404 responses X% of the time.

使用 API 搜索单词或在随机"中挑选的短语并对其进行抽样结果.如果你这样做,你应该考虑使用什么值orderby= URL 参数.默认排序是相关性",即将导致最好的结果是我们的算法认为的结果与您的搜索词最相关.这可能会扭曲您的如果你总是抓住第一个条目或类似的结果.你也可以按已发布"排序,这将为您提供按时间顺序排列的提要视频.

You might have better luck just using the API to search for words or phrases that are picked at "random" and taking a sampling of the results. If you do that, you should think about what value to use for the orderby= URL parameter. The default ordering is "relevance", which will lead to the top results being the ones that our algorithms think are the most relevant to your search terms. This might skew your results if you always grab the first entry or the like. You could also order by "published" which will give you a reverse-chronological feed of videos.

干杯,-Jeff Posnick,YouTube API 团队作为关于 randomyoutubevideo.net,该网站的关于"页面是这样说的:

Cheers, -Jeff Posnick, YouTube API Team as With regards to randomyoutubevideo.net, this is what the "About" page of that site has to say:

那么,我们如何才能提供真正随机的 YouTube 视频链接?事实证明YouTube 编程接口 (API) 提供了额外的允许发现更多视频的功能随机的.使用一些技巧,结合一点操作在时空结构中,我们设法创建了一个过程,生成真正随机的 YouTube 视频链接.

So how can we provide truly random links to YouTube videos? It turns out that the YouTube programming interface (API) provides additional functions that allow the discovery of videos that are much more random. Using a number of tricks, combined with a little manipulation of the space-time frabric, we have managed to create a process that yiields truly random links to YouTube videos.

此页面上的随机 YouTube 功能目前使用数据库.随着时间的推移,我们将扩展这个数据库,并根据需求,可以通过 API 免费提供.

The random YouTube function on this page currently uses a subset of the database. Over time we will expand this database and, depending on demand, may make it available free of charge via an API.

我理解这意味着他们一直在从 API 中提取大量视频,并从中随机选择视频的数据库.

I understand this to mean that they have been pulling large lists of videos from the API and making a DB of them from which they randomly select.

这篇关于如何使用 YouTube API 获取随机的 YouTube 视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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