【问题标题】:How to get YouTube channel name and URL after authenticating验证后如何获取 YouTube 频道名称和 URL
【发布时间】:2015-07-24 23:57:47
【问题描述】:

一旦我对用户进行了身份验证 - 例如在下面的代码中 - 我如何才能找到他们的频道名称和频道 URL?

我正在使用带有 .NET 库的 YouTube 数据 api v3:

UserCredential credential;
  using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
  {
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        new[] { YouTubeService.Scope.YoutubeReadonly },
        "user",
        CancellationToken.None,
        new FileDataStore(this.GetType().ToString())
    );
  }

  var youtubeService = new YouTubeService(new BaseClientService.Initializer()
  {
    HttpClientInitializer = credential,
    ApplicationName = this.GetType().ToString()
  });

【问题讨论】:

    标签: google-api google-oauth youtube-data-api


    【解决方案1】:

    终于想出办法了。从身份验证中获取令牌后,请执行以下操作:

    var channelsListRequest = _youTubeService.Channels.List("id,snippet");
    
    channelsListRequest.Mine = true;
    
    var channelsListResponse = channelsListRequest.Execute();
    
    if (    (null != channelsListResponse)          && 
            (null != channelsListResponse.Items)    &&
            (channelsListResponse.Items.Count > 0)  )
    {
        Channel userChannel = channelsListResponse.Items[0];
    
        string youtubeUserID = userChannel.Id;
        string ytChannelURL = "https://www.youtube.com/channel/" + userChannel.Id;
        string name = userChannel.Snippet.Title;
    }
    

    呼!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-22
      • 2014-11-17
      • 2020-11-26
      • 2014-08-16
      • 2017-04-10
      • 2018-10-28
      • 1970-01-01
      • 2018-04-16
      相关资源
      最近更新 更多