我可以使用以下代码将视频成功上传到C#中的我的YouTube帐户:
private async Task Run(string videoFile, string dateStamp)
{
UserCredential credential;
using (var stream = new FileStream("client_secrets.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.Youtubepartner},
"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 = string.Format("{0} - La Jolla boat launch timelapse", dateStamp);
video.Snippet.Description = "Daily TimeLapse of the boat launch area.";
video.Snippet.Tags = new string[] { "LaJolla", "timelapse" };
video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
video.Snippet.ChannelId = "UC8LB7gACPEoNxdAK6LM-L6A";
video.Snippet.ChannelTitle = "TimeLapse La Jolla";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public"; // or "private" or "public"
var filePath = videoFile; // Replace with path to actual movie file.
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();
}
}
但是,我的YouTube帐户中有3个频道,并希望上传到特定频道。上面的代码将上传到我的主帐户而不会出现问题,但不会上传到提供的渠道ID。频道名称和ID是正确的 - 但这不起作用,因为我希望视频在频道中显示为新上传。我无法找到此功能的其他信息。有什么建议吗?
代码来自youtube API示例。
感谢您的光临。