在 C# 中使用 Youtube API V3 从频道获取视频 [英] Get Videos from a Channel using Youtube API V3 in C#

查看:23
本文介绍了在 C# 中使用 Youtube API V3 从频道获取视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.Net 网页,我在其中使用 V2 显示来自我频道的 Youtube 视频.由于谷歌已停用 V2 API,我尝试使用 V3 API,但无法从频道获取视频.

I have a ASP.Net webpage where I was displaying Youtube Videos from my channel using V2. Since Google has retired V2 API, I am trying to use V3 API, but unable to get the videos from the channel.

我确实查看了 github 上的示例,但示例显示了如何创建视频,但无法检索视频.搜索 SO,我看到使用 php 库的示例,我正在寻找特定于 C# 的内容.

I did look at the samples at github, but the example shows how to create a video, but no way to retrieve videos. Searching on SO, I see examples using php library, I am looking something specific to C#.

有人可以帮我解决这个问题吗?

Can anyone help me with regard to this?

推荐答案

通过将频道 ID 添加到 Search.list 它返回频道中的视频列表.

By adding channel id to Search.list it returns a list of the videos in the channel.

var searchListRequest = service.Search.List("snippet");
searchListRequest.ChannelId = "UCIiJ33El2EakaXBzvelc2bQ";
var searchListResult = searchListRequest.Execute();

更新对正在发生的事情的评论解释的回复:

实际上搜索会返回与频道 ID 关联的所有内容,毕竟您是在搜索频道 ID.

Actually search returns everything associated with the channel id, you are after all searching on a channel id.

Search 返回一个包含许多项目的 SearchListResponse.每个项目属于 SearchResource 类型搜索资源可以有不同的类型或种类.在下面的两张图片中,您可以看到第一个是 kind youtube#channel 第二个是 kind youtube#video 您可以通过它们循环并找到youtube 视频.如果您滚动到 search.list 页面的底部,您可以尝试查看 API 返回的原始 JSon.

Search returns a SearchListResponse which contains a number of items. Each item is of type SearchResource search resources can have different types or Kinds. In the two pictures below you can see that the first one is kind youtube#channel the second is kind youtube#video it will be up to you to loop though them and find the youtube videos. if you scroll to the bottom of the search.list page you can try it and see the raw JSon that the API is returning.

解决方案:

现在,如果您只想取回视频,您可以通过在请求中添加类型来告诉它您想要的只是视频:

Now if all you want to do is get the videos back you can just tell it that all you want are videos by adding type to your request:

searchListRequest.Type = "video";

这篇关于在 C# 中使用 Youtube API V3 从频道获取视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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