使用 .NET API 搜索 YouTube
我正在尝试使用 YouTube API 通过搜索文本来搜索 YouTube。示例代码如下。
using Google.YouTube;
using Google.GData.YouTube;
using Google.GData.Client;
using Google.GData.Extensions;
(..)
YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
//order results by the number of views (most viewed first)
query.OrderBy = "viewCount";
// search for puppies and include restricted content in the search results
// query.SafeSearch could also be set to YouTubeQuery.SafeSearchValues.Moderate
query.Query = "puppy";
query.SafeSearch = YouTubeQuery.SafeSearchValues.None;
Feed<Video> videoFeed = request.Get<Video>(query);
printVideoFeed(videoFeed);
我的问题是 query.Query
、request
和 printVideoFeed
不存在 - 如何使用 API 搜索 YouTube?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然您可以使用YouTube .NET 客户端库,但我发现.NET API 落后于协议本身的开发(例如,我不确定您是否还可以从 API 中获取喜欢/不喜欢的信息)。
相反,我建议您使用数据 API 协议,它使用 HTTP 和 XML(采用 ATOM 格式),.NET 具有可以轻松实现的类使用/解析。文档也非常完整,编写查询将非常容易。
在您的示例中,查询的 URL 为:
http://gdata.youtube.com/feeds/api/videos?v=2&orderby=viewCount&safeSearch=none&q=puppy
随后将返回一个 XML 文档,其结构如下(虽然数据可能不同,因为我假设小狗的新视频一直在上传):
您还可以获取 XML 并将其放入 YouTube .NET 客户端结构中以便于访问(尽管不是很容易,这是可能的)如果您想利用他们已有的对象模型,但需要下拉到 XML 来获取 API 未公开的值。
While you can use the .NET client library for YouTube, I find that the .NET API lags behind the developments that are being made (for example, I'm not sure if you can even get the like/dislike information from the API yet) in the protocol itself.
Instead, I'd recommend that you use the Data API Protocol, it uses HTTP and XML (in ATOM format) which .NET has classes that can easily use/parse. The documentation is also very complete, and composing your queries would be quite easy.
In your example, the URL for your query would be:
http://gdata.youtube.com/feeds/api/videos?v=2&orderby=viewCount&safeSearch=none&q=puppy
Which would subsequently return an XML document structured like this (although the data might be different, as I assume new videos of puppies are being uploaded all the time):
You can also get the XML and put it into the YouTube .NET client structures for easy access (although not easily, it is possible) if you want to capitalize on the object models that they already have, but drop down to the XML to get values that the API doesn't expose.
您要查找的内容位于其 .NET 指南的身份验证章节。
基本上,您需要在开头添加此内容:
printVideoFeed
方法只是打印所有元数据的演示,但您可以在 也在指南中。您可能想用获得的Feed
做其他事情。不过
query.Query
不应该丢失。What you're looking for is in the Authentication chapter of their .NET guide.
Basically, you need to add this in the beginning:
The
printVideoFeed
method is just a demo to print out all the meta-data, but you can find it in the guide too. You probably want to do something else with theFeed
you get.query.Query
shouldn't be missing though.