【问题标题】:Authorized failed when run Google.Apis.YouTube.Samples.Upload project from Github从 Github 运行 Google.Apis.YouTube.Samples.Upload 项目时授权失败
【发布时间】:2017-12-06 11:33:27
【问题描述】:

我是 youtube api 的新手。我想要一个控制台程序安排每次都未经授权将视频上传到 youtube。

我看到很多帖子和视频,但不是完整的故事,我从 Github 下载了示例并尝试运行它。它失败了。

我按照指南

。创建 OAuth 客户端 ID 和应用程序类型选择其他

。从github下载代码

。在浏览器中点击允许,让youtube api管理youtube账号。

img1 - client secret download from console developer and code from github

img2 - error message told me unauthorized

哪一部分有问题,我该如何解决?请帮忙!

【问题讨论】:

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


【解决方案1】:

您收到的错误意味着您尚未对 YouTubeService 进行身份验证,您的凭据一定有问题,我看不到,因为您尚未发布所有代码。

YouTube API 不支持服务帐户。您将需要至少验证一次您的代码。这是通过网络浏览器完成的,您使用的客户端库会将“用户”的凭据存储在 %appData% 目录中。

您所遵循的教程没有说明不需要身份验证。这是授权的代码。

UserCredential credential;
      using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
      {
        credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            GoogleClientSecrets.Load(stream).Secrets,
            // This OAuth 2.0 access scope allows for full read/write access to the
            // authenticated user's account.
            new[] { YouTubeService.Scope.Youtube },
            "user",
            CancellationToken.None,
            new FileDataStore(this.GetType().ToString())
        );
      }

【讨论】:

  • 示例程序还包括您提供的部分代码。我是新人,所以我只能在帖子中发布两个链接。
  • @Dalm,和你的完全一样,但是错误是未经授权的。网络、代理、防火墙有影响吗?
猜你喜欢
  • 1970-01-01
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-10
  • 1970-01-01
  • 2014-01-25
  • 1970-01-01
相关资源
最近更新 更多