i am trying to upload a video to YouTube by using YouTube data API, from my application but unfortunately the API which provided by YouTube developers
is not working before three weeks i tested the code and it was working fine but now when i try to finally use it in my application its causing a problem all the code is working fine but when the video uploading process starts it's became loading and loading and the video doesn't uploaded i google it but not find any help. if some one can help me ?
What I have tried:
i have tried this code
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("G:\\client_secret_783534382593-0cn4gm229raqq97kdu0ghsj9hqfsc5o1.apps.googleusercontent.com.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
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 = "ttry";
video.Snippet.Description = " Video Description";
video.Snippet.Tags = new string[] { "tag1s", "tag2s" };
video.Snippet.CategoryId = "22";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "public";
var filePath = "F:\\Dna.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;
}
}
void videosInsertRequest_ResponseReceived(Video video)
{
Console.WriteLine("Video id '{0}' was successfully uploaded.", video.Id);
}
}
}
and i called it simply from this action
public ActionResult Contact()
{
Run().Wait();
return View();
}
i wonder that why it is not working ? when i debug it then all the things and parameters are fine even credentials are also fine but at the end the file is not uploading even i am selecting 1 MB file and i also included all the necessary NuGet packages kindly some one help me please ?