【问题标题】:Youtube Live API - Broadcast premission denied using OAuthYoutube Live API - 使用 OAuth 拒绝广播权限
【发布时间】:2017-01-16 10:16:07
【问题描述】:

我正在尝试使用 Youtube.Data.Api v3 从我的 .Net 应用程序进行直播。 我已经设置了 OAuth 并下载了 .JSON 文件,并且工作正常。我知道,因为我已经成功获得了频道列表。我帐户上的视频,即以下代码有效:

var channelsRequest = ytService.Channels.List("contentDetails, snippet");
channelsRequest.Mine = true;
var channelsListResponse = channelsRequest.Execute();

但如果我尝试执行插入请求(为了完整起见,我会向您展示整个方法),

public static LiveBroadcast CreateImmediateBroadcast(string title = "DefaultBroadcast") {
    var snippet = new LiveBroadcastSnippet();
    snippet.Title = title;
    snippet.ScheduledStartTime = DateTime.Now;
    snippet.ScheduledEndTime = DateTime.Now + TimeSpan.FromMinutes(60);

    var status = new LiveBroadcastStatus();
    status.PrivacyStatus = "unlisted";

    var broadcast = new LiveBroadcast();
    broadcast.Kind = "youtube#liveBroadcast";
    broadcast.Snippet = snippet;
    broadcast.Status = status;

    var insertBroadcastRequest = ytService.LiveBroadcasts.Insert(broadcast, "snippet, status");
    insertBroadcastRequest.Execute();
    return broadcast;
}

调用insertBroadcastRequest.Execute()时出现异常,即:

Google.GoogleApiException 未处理

HResult=-2146233088 Message=Google.Apis.Requests.RequestError

权限不足 [403] 错误 [ Message[Insufficient Permissions] Location[-] Reason[insufficientPermissions] Domain[global] ] 服务名称=youtube

Source=Google.Apis

堆栈跟踪: 在 C:\Users\cloudsharp\Documents\GitHub\google-api-dotnet-client\Src\Support\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 96 中的 Google.Apis.Requests.ClientServiceRequest`1.Execute() 在 C:\Users\bussg\Source\Workspaces\OwnExperimental\YoutubeConsole\YoutubeConsole\YouTubeAPI.cs: 87 中的 YoutubeConsole.YouTubeAPI.CreateImmediateStream(String title) 在 YoutubeConsole.YouTubeAPI.Test() 中 ...

另外,为了完整起见,这是我的授权,

using (var stream = new FileStream(Directory.GetCurrentDirectory() + @"\GoogleAuthOtherApplication.json", FileMode.Open, FileAccess.Read)) {
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
        GoogleClientSecrets.Load(stream).Secrets,
        new[] { YouTubeService.Scope.YoutubeForceSsl},
        "user",
        CancellationToken.None,
        new FileDataStore("YouTubeAPI")
    ).Result;
}

另外,对于YouTubeService.Scope,我已经尝试了所有选项。根据documentationinsert 方法应该与ForceSsl 一起使用。

还有this documentation pagesais

注意:频道必须获得批准才能使用 YouTube 直播功能,该功能使频道所有者能够将直播内容流式传输到该频道。如果您代表一个经过身份验证的用户发送 API 请求,该用户的频道未启用或没有资格流式传输直播内容,则 API 将返回不足权限错误。

但我所有的频道都已获准用于 Youtube Live。任何想法如何让它发挥作用?

【问题讨论】:

  • 您可能必须成为 YouTube 内容合作伙伴。或者这个support.google.com/youtube/answer/2474026?hl=en
  • @DalmTo:我已经多次浏览了许多文档页面,他们没有提到必须成为内容合作伙伴(如果你想在你的流中显示广告,你只需要它。而且关于您的链接:还检查了,我的频道可以不受限制地进行直播。
  • 你在世界的什么地方?
  • @DalmTo:在德国莱比锡。为什么?
  • Domain[global] 让我想知道它是否是位置歧视的事情。我从未尝试过直播,但我可以从丹麦测试你的代码,看看我是否得到同样的结果。

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


【解决方案1】:

在我们之间通过电子邮件进行一些测试后,好的。

  1. 您需要通过更改“用户”来获得正确的范围“YouTubeService.Scope.YoutubeForceSsl”,我们强制它再次请求权限。我的 tutorial 关于文件数据存储在 Google .net 客户端库中的工作原理

  2. 通过发送对我有用的“sn-p,status”来删除空格“sn-p,status”。

为了好玩:Issue 8568:LiveBroadcasts: insert - spaces in part

【讨论】:

  • 谢谢!让我添加以下内容:“状态”和“sn-p”不能单独工作。只有包含“status”和“sn-p”(可能还有更多字符串)且没有空格的请求有效。
  • livestreams.insert 请求也会出现类似的问题。有必要在请求中包含“sn-p”和“cdn”作为部分参数。
  • 感谢您让我使用新的 API :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-13
  • 1970-01-01
  • 2011-04-18
  • 2019-10-24
  • 2018-01-20
  • 2019-08-20
  • 1970-01-01
相关资源
最近更新 更多