1

我试图仅基于特定视频的视频名称搜索出现在我的频道中的视频。但是,当我尝试下面的代码时,我看到了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))); 
    } 
    } 
} 

回答

1

按照documentation,你可以在搜索请求中使用“渠道ID”参数。

searchListRequest.ChannelId = {YOUR_CHANNEL_ID}; 

(我不是一个C#的人。请检查属性名)

相关问题