gpt4 book ai didi

c# - 使用C#从我的youtube视频 channel 中搜索上传的youtube视频

转载 作者:行者123 更新时间:2023-12-03 06:22:06 25 4
gpt4 key购买 nike

在YouTube中,请帮助我搜索我在YouTube channel 中上传的视频。
这是我正在尝试的代码。

namespace Google.Apis.YouTube.Samples
{

that you have enabled the YouTube Data API for your project.
/// </summary>
internal class Search
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("YouTube Data API: Search");
Console.WriteLine("========================");

try
{
new Search().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("Error: " + e.Message);
}
}

Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}

private async Task Run()
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "API KEY ",
ApplicationName = "YouTubeUpload"
});

var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = "T52cSiV4vV8"; // Replace with your search term.
searchListRequest.MaxResults = 50;

// Call the search.list method to retrieve results matching the specified query term.
var searchListResponse = await searchListRequest.ExecuteAsync();

List<string> videos = new List<string>();
List<string> channels = new List<string>();
List<string> playlists = new List<string>();
foreach (var searchResult in searchListResponse.Items)
{
switch (searchResult.Id.Kind)
{
case "youtube#video":
videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
break;

case "youtube#channel":
channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId));
break;

case "youtube#playlist":
playlists.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId));
break;
}
}

Console.WriteLine(String.Format("Videos:\n{0}\n", string.Join("\n", videos)));
Console.WriteLine(String.Format("Channels:\n{0}\n", string.Join("\n", channels)));
Console.WriteLine(String.Format("Playlists:\n{0}\n", string.Join("\n", playlists)));
}
}
}

在运行上面的代码时,我收到“Bad Request 400”异常 Exception screenshot

我错过了什么吗?

最佳答案

您需要在Google Console Developer中使用API​​key设置字段“ApiKey”

首先,为您的项目启用Youtube Data API,然后创建凭据以获取APIKey。

关于c# - 使用C#从我的youtube视频 channel 中搜索上传的youtube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33101954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com