【问题标题】:Searching an uploaded youtube video from my youtube video channel using c#使用 c# 从我的 youtube 视频频道搜索上传的 youtube 视频
【发布时间】:2016-01-11 03:52:53
【问题描述】:

在 Youtube 中,请帮助我搜索我上传到我的 youtube 频道的视频.. 这是我正在尝试的代码..

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)));
    }
  }
}

在运行上述代码时,我收到“错误请求 400”异常Exception screenshot

我错过了什么吗??

【问题讨论】:

    标签: c# video youtube youtube-channels


    【解决方案1】:

    您需要在Google Console Developer 中为您的 APIkey 设置一个字段“ApiKey”

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

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    • 哦,对不起。这是我的第一个答案:)。下次我会努力做得更好。
    猜你喜欢
    • 2016-01-13
    • 2015-07-12
    • 1970-01-01
    • 2013-07-02
    • 1970-01-01
    • 2014-05-09
    • 2013-06-27
    • 2014-11-04
    • 1970-01-01
    相关资源
    最近更新 更多