搜索视频从Youtube频道,这是上载仅在该频道根据视频名称



我正试图搜索仅基于特定视频的视频名称存在于我的频道中的视频。然而,当我尝试下面的代码,我看到所有的视频都存在于YouTube相关的搜索关键字。我想只获取在我的频道中存在的视频。使用所有必需的最新库

代码在这里

    private async Task Run()
    {
      var youtubeService = new YouTubeService(new BaseClientService.Initializer()
      {
        ApiKey = "My API Key ",//"REPLACE_ME",
        ApplicationName = this.GetType().ToString()
      });
      var searchListRequest = youtubeService.Search.List("snippet");
      searchListRequest.Q = "MYVID"; // 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)));
    }
  }
}

根据文档,您可以在搜索请求中使用'channelId'参数。

searchListRequest.ChannelId = {YOUR_CHANNEL_ID};
我不是一个c#的人。

相关内容

  • 没有找到相关文章

最新更新