为什么 Youtube 的 v3 API 声称我的访问令牌无权插入直播流?



在我的应用程序的授权阶段,我请求访问:

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

这成功地为我获得了访问令牌和刷新令牌。现在我想插入一个新的流基于信息在谷歌api文档

  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资源管理器

显然,我看错了(谷歌的API文档应该真正描述这一点)。

回应不是我没有访问适当的范围,它是,即使我授权自己的youtube范围,我的youtube帐户没有启用直播流(单独的选项)。

在我的帐户上启用直播后,此代码正常工作。

相关内容

  • 没有找到相关文章

最新更新