【问题标题】:searching video from Youtube channel which are uploaded only in that channel depending on the video Name根据视频名称从 Youtube 频道搜索仅在该频道上传的视频
【发布时间】:2016-01-13 10:51:29
【问题描述】:

我正在尝试仅根据特定视频的视频名称来搜索我频道中的视频。但是,当我尝试以下代码时,我看到 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)));
    }
  }
}

【问题讨论】:

    标签: c# youtube-api youtube-data-api google-api-dotnet-client youtube-channels


    【解决方案1】:

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

    searchListRequest.ChannelId = {YOUR_CHANNEL_ID};
    

    (我不是c#人,请检查属性名)

    【讨论】:

      猜你喜欢
      • 2014-10-13
      • 2016-01-11
      • 1970-01-01
      • 2013-07-02
      • 2019-08-16
      • 2018-09-16
      • 2023-03-10
      • 2015-07-12
      • 2020-01-09
      相关资源
      最近更新 更多