i am using c#, i can upload video youtube my channel successfully. Now i want to upload video include thumbnail. I got no error in debug but the thumbnail did not upload, here is my code:
private static async Task Upload(FileInfo Vidf)
{
//2.1 Get credentials
UserCredential credentials;
//2.1.1 Use https://console.developers.google.com/ to get the json file (Credential section)
using (var stream = new FileStream(APIjson, FileMode.Open, FileAccess.Read))
{
credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None);
}
//2.2 Create a YoutubeService instance using our credentials
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credentials,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
//2.3 Create a video object
var video = new Video()
{
Id = Vidf.Name,
Status = new VideoStatus
{
PrivacyStatus = "private"
},
Snippet = new VideoSnippet
{
Title = "...",
Description = "...",
}
};
var filePath = Vidf.FullName;
filesize = Vidf.Length;
//2.4 Read and insert the video in youtubeService
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
videosInsertRequest.ProgressChanged += ProgressChanged;
videosInsertRequest.ResponseReceived += ResponseReceived;
//2.4.1 Wait for the upload process
await videosInsertRequest.UploadAsync();
}
var tpath = Vidf.FullName.Replace("mp4", "jpg");
using (var tStream = new FileStream(tpath, FileMode.Open))
{
var tInsertRequest = youtubeService.Thumbnails.Set(video.Id, tStream, "image/jpeg");
tInsertRequest.ProgressChanged += ProgressChanged;
await tInsertRequest.UploadAsync();
}
}
Do i have to upload video first and wait finished youtube processing the video. Then upload thumbnails like example code in this link https://developers.google.com/youtube/v3/docs/thumbnails/set#examples