Youtube Live API - 使用 OAuth 拒绝广播许可
Youtube Live API - Broadcast premission denied using OAuth
我正在尝试使用 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 was unhandled
HResult=-2146233088
Message=Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]
ServiceName=youtube
Source=Google.Apis
StackTrace:
at Google.Apis.Requests.ClientServiceRequest`1.Execute() in C:\Users\cloudsharp\Documents\GitHub\google-api-dotnet-client\Src\Support\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 96
at YoutubeConsole.YouTubeAPI.CreateImmediateStream(String title) in C:\Users\bussg\Source\Workspaces\OwnExperimental\YoutubeConsole\YoutubeConsole\YouTubeAPI.cs:line 87
at YoutubeConsole.YouTubeAPI.Test() in
...
此外,为了完整起见,这是我的授权,
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
我已经尝试了所有选项。根据 documentation.
,insert
方法应与 ForceSsl
一起使用
Note: A channel must be approved to use the YouTube Live feature, which enables the channel owner to stream live content to that channel. If you send API requests on behalf of an authenticated user whose channel is not enabled or eligible to stream live content, the API will return an insufficientPermissions error.
但是我的所有频道都已获准用于 Youtube Live。有什么想法可以让它发挥作用吗?
好的,我们之间通过电子邮件进行了一些测试。
您需要通过更改 "user" 获得正确的范围 "YouTubeService.Scope.YoutubeForceSsl" 我们强制它再次请求权限。我的 tutorial 关于文件数据存储在 Google .net 客户端库中的工作方式
通过发送 "snippet,status" 删除 space "snippet, status" 它对我有用。
我正在尝试使用 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 was unhandled
HResult=-2146233088 Message=Google.Apis.Requests.RequestError
Insufficient Permission [403] Errors [ Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global] ] ServiceName=youtube
Source=Google.Apis
StackTrace: at Google.Apis.Requests.ClientServiceRequest`1.Execute() in C:\Users\cloudsharp\Documents\GitHub\google-api-dotnet-client\Src\Support\GoogleApis\Apis\Requests\ClientServiceRequest.cs:line 96 at YoutubeConsole.YouTubeAPI.CreateImmediateStream(String title) in C:\Users\bussg\Source\Workspaces\OwnExperimental\YoutubeConsole\YoutubeConsole\YouTubeAPI.cs:line 87 at YoutubeConsole.YouTubeAPI.Test() in ...
此外,为了完整起见,这是我的授权,
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
我已经尝试了所有选项。根据 documentation.
insert
方法应与 ForceSsl
一起使用
Note: A channel must be approved to use the YouTube Live feature, which enables the channel owner to stream live content to that channel. If you send API requests on behalf of an authenticated user whose channel is not enabled or eligible to stream live content, the API will return an insufficientPermissions error.
但是我的所有频道都已获准用于 Youtube Live。有什么想法可以让它发挥作用吗?
好的,我们之间通过电子邮件进行了一些测试。
您需要通过更改 "user" 获得正确的范围 "YouTubeService.Scope.YoutubeForceSsl" 我们强制它再次请求权限。我的 tutorial 关于文件数据存储在 Google .net 客户端库中的工作方式
通过发送 "snippet,status" 删除 space "snippet, status" 它对我有用。