我使用YouTube API v3將視頻上傳到YouTube。我目前能夠上傳視頻,更新標題和說明,但對我而言非常重要的是取消選中(boolean false)NotifySubscribers屬性。C#設置YouTube上的NotifySubscribers .Videos.Insert與YouTube API v3
我已經能夠找到文檔here和here,但沒有任何實現的例子,我感覺很迷茫。
以下是我的代碼目前有能夠成功上傳,無需NotifySubscribers設置爲false:
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("youtube_client_secret.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "test";
video.Snippet.Description = "test description";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"
var filePath = @"D:\directory\YoutubeUploader\2017-02-05_02-01-32.mp4";
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += videosInsertRequest_ProgressChanged;
videosInsertRequest.ResponseReceived += videosInsertRequest_ResponseReceived;
await videosInsertRequest.UploadAsync();
}
}
void videosInsertRequest_ProgressChanged(Google.Apis.Upload.IUploadProgress progress)
{
switch (progress.Status)
{
case UploadStatus.Uploading:
Console.WriteLine("{0} bytes sent.", progress.BytesSent);
break;
case UploadStatus.Failed:
Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
break;
}
}
我本來以爲,設置該值會一直如設置標題一樣簡單,隱私身份等等,但這似乎並非如此。我從來沒有做過任何真正深入的C#編碼,因此其中一些概念對我來說是非常新的。
嘗試更改隱私狀態公衆,這[論壇](https://productforums.google.com/forum/# !topic/youtube/GjIoVHR3f7M; context-place = topicsearchin/youtube/category $ 3Asafari)討論過,任何視頻上傳爲私有/不公開,都可能導致該用戶不被通知。如果您已爲每次上傳完成手動勾選通知訂閱者,請查看您的YouTube頻道。默認情況下,[notifySubscribers](https://developers.google.com/youtube/v3/docs/videos/insert#parameters)設置爲** True **。 –