问题
I am using Google "Client Library for .NET" for YouTube service.
And when i try to upload video i got Error.(System.ArgumentNullException) from my [Videos.Insert] request.
ArgumentNullException: Value cannot be null. Parameter name: baseUri
Stack:
в Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
в Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
в Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
в Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
в Google.Apis.Upload.ResumableUpload`1.<UploadCoreAsync>d__e.MoveNext() в c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\[Media]\Upload\ResumableUpload.cs:строка 459
My code:
X509Certificate2 certificate = new X509Certificate2(@"test.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("test@developer.gserviceaccount.com")
{
Scopes = new[] { YouTubeService.Scope.YoutubeUpload, YouTubeService.Scope.Youtube, YouTubeService.Scope.YoutubeReadonly }
}.FromCertificate(certificate));
if (credential.RequestAccessTokenAsync(CancellationToken.None).Result)
{
String AuthenticationKey = credential.Token.AccessToken;
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApplicationName = "test",
HttpClientInitializer = credential
});
var video = new Video();
video.Snippet = new VideoSnippet();
video.Snippet.Title = "Test Video";
video.Snippet.Description = "Test Vide Description";
video.Snippet.Tags = new string[] { "test" };
video.Snippet.CategoryId = "22";
video.Status = new VideoStatus();
video.Status.PrivacyStatus = "private";
var filePath = @"test.mp4";
using (var fileStream = new FileStream(filePath, FileMode.Open))
{
var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
var uploadResult = videosInsertRequest.Upload();
uploadResult = uploadResult;
}
Can Anyone help?
回答1:
I have also got the same problem, fiddler shows the response as follows.
{ "error": { "code": 500, "message": null } }
回答2:
It not your code problem, we all are getting same error. Issue raise here: https://code.google.com/p/gdata-issues/issues/detail?id=6352.
来源:https://stackoverflow.com/questions/23156369/youtube-upload-file-give-me-argumentnullexception-c