我試圖通過編程方式在YouTube上創建實時流,但出現錯誤。我創建了一個服務帳戶(將從Web服務器應用程序的後臺運行)。當我嘗試執行livebroadcast插入請求時,出現錯誤「用戶未啓用實時流媒體。[403]」。YouTube數據API - 創建實況廣播 - 獲取[liveStreamingNotEnabled] - 但它是
但是,事情就是這樣,帳戶唯一的「用戶」是我,我已啓用實時流式傳輸。我假設這個權限將被執行api調用的服務帳戶共享。如果情況並非如此,那麼如何爲服務帳戶用戶啓用直播?
這是我的代碼。任何幫助將不勝感激。
String serviceAccountEmail = "XXX";
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] {
YouTubeService.Scope.Youtube
}
}.FromCertificate(certificate));
// Create the service.
var service = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "My App",
});
LiveBroadcast broadcast = new LiveBroadcast();
LiveBroadcastSnippet snippet = new LiveBroadcastSnippet();
snippet.ScheduledStartTime = new DateTime(2015, 6, 1, 14, 25, 0);
snippet.ScheduledEndTime = new DateTime(2015, 6, 1, 15, 25, 0);
snippet.Title = "Test Event";
broadcast.Kind = "youtube#liveBroadcast";
broadcast.Snippet = snippet;
LiveBroadcastStatus status = new LiveBroadcastStatus();
status.PrivacyStatus = "unlisted";
broadcast.Status = status;
LiveBroadcastsResource.InsertRequest request = service.LiveBroadcasts.Insert(broadcast, "snippet,status");
broadcast = request.Execute();
什麼是你想流的來源? 「以編程方式」是什麼意思? –
在能夠流式傳輸之前,您需要創建一個livebroadcast。我想創建使用代碼的livebroadcast(如上)。這是一個事件,將有數百個實時流,其中許多將同時運行。 –