1

我正在使用 Google YouTube .NET API 版本 3。我添加了以下 nuget 包

正如 Youtube 开发者示例中给出的,我可以对单个搜索查询进行单个搜索。如何一次性批量处理几个搜索查询。从开发人员文档中我知道我可以执行 50 次操作。(任何 50 CRUD)。如何使用 .NET 客户端库来做到这一点?你能给我一个代码示例吗?到目前为止,我正在关注这个例子

按关键字搜索

 private async Task Run()
    {
      var youtubeService = new YouTubeService(new BaseClientService.Initializer()
      {
        ApiKey = "REPLACE_ME",
        ApplicationName = this.GetType().ToString()
      });

  var searchListRequest = youtubeService.Search.List("snippet");
  searchListRequest.Q = "Google"; // 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>();

  // Add each result to the appropriate list, and then display the lists of
  // matching videos, channels, and playlists.
  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)));
}
4

0 回答 0