c# - 为什么YouTube的v3 API声称我的访问 token 没有插入实时流的权限?

标签 c# youtube youtube-api google-oauth

在我的应用程序的授权阶段,我请求通过以下方式进行访问:

  var req = new Google.Apis.Auth.OAuth2.Requests.GoogleAuthorizationCodeRequestUrl(new Uri(string.Format(Settings.Google.OAuth.Url, "auth")));
  req.ClientId = Settings.Google.OAuth.ClientId;
  req.ResponseType = "code";
  req.Scope = "https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner";
  req.RedirectUri = string.Format(Settings.Integration.HandshakeUrl, "youtube");
  req.AccessType = "offline"; // required to get refreshToken.
  req.ApprovalPrompt = "force";

  req.State = Application.Cryptography.Encrypt(Application.JSON.SerializeToString<State>(new State { UID = userId, PROFILEID = profileId, SUCCESS = request.SuccessUrl, FAIL = request.FailUrl }), Settings.Cryptography.SymetricKey);

  // Return the url that the requesting application should redirect to in order to perform the authorization.
  return req.Build().ToString();

这样可以成功获取访问 token 和刷新 token 。现在,我想根据信息in the google api docs插入新的流
  var token = new Google.Apis.Auth.OAuth2.Responses.TokenResponse { RefreshToken = refreshToken, AccessToken = accessToken };
  var credentials = new UserCredential(new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
  {
    ClientSecrets = new ClientSecrets
    {
      ClientId = "<id>",
      ClientSecret = "<secret>",
    }
  }), string.Empty, token);

  var service = new YouTubeService(new BaseClientService.Initializer
  {
    HttpClientInitializer = credentials
  });

  var streamResource = new LiveStreamsResource(service);
  var result = streamResource.Insert(new LiveStream
  {
    Snippet = new LiveStreamSnippet
    {
      Title = "Stream"
    },

    Cdn = new CdnSettings
    {
      Format = "1080p",
      IngestionType = "rtmp"
    }
  }, "id, snippet, cdn, status");

  var returnedStream = result.Execute();

在运行时Execute()给出以下异常:
Google.Apis.Requests.RequestError

Request is not authorized [403]

Errors [

    Message[Request is not authorized] Location[ - ] Reason[insufficientLivePermissions] Domain[youtube.liveStream]

]

我无法弄清楚我在此过程中做错了什么。甚至API Explorer

最佳答案

显然,我是在看所有错误(Google的API文档应该对此进行了描述)。

答案不是我没有访问适当的范围,而是即使我授权自己使用youtube范围,我的youtube帐户也没有启用实时流(单独的选项)。

在我的帐户上启用实时流式传输后,此代码正常运行。

关于c# - 为什么YouTube的v3 API声称我的访问 token 没有插入实时流的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24131310/

相关文章:

javascript - ASP.Net MVC Razor 文档下载已损坏

javascript - 使用 YouTube API 构建允许 YouTube 搜索的页面

jquery - 返回嵌入 YouTube 当前时间

c# - 关闭连接时出现“Only assignment, call increment…”错误

c# - 无论如何需要 DBNull 做什么?

c# - 有没有办法更改 azure 函数的 blob 绑定(bind)中的 blob 路径?

javascript - 我无法让 Youtube API 在 Squarespace 中工作

youtube - 是否可以通过API查看或添加到YouTube分析视频组?

youtube iframe api 通过 ajax

android - 使用播放列表网址获取YouTube视频