YouTube上传文件给我ArgumentNullException(C#) [英] YouTube upload file give me ArgumentNullException (C#)

查看:706
本文介绍了YouTube上传文件给我ArgumentNullException(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用谷歌的客户端库.NETYouTube的服务。
当我尝试上传的视频,我得到的错误。(System.ArgumentNullException)从我的[Videos.Insert]的要求。

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

堆栈:

в 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

我的code:

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;
          }

谁能帮助?

推荐答案

我也得到了同样的问题,小提琴手显示响应如下:

I have also got the same problem, fiddler shows the response as follows.

{  错误: {   code:500,   消息:空  } }

{ "error": { "code": 500, "message": null } }

这篇关于YouTube上传文件给我ArgumentNullException(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆