1

I am using youtube API version three.

Trying to upload the video through a web application.

When I am using my own account I could be able to upload the video but when I use credentials from client it's failing now and it worked before.

Getting the error message saying {"Value cannot be null.\r\nParameter name: baseUri"}.

Are there any limitations to uploading videos?

I could be upload 70+ videos successfully before this error came Could you please help me on solve this

var guid = "";
try
        {
            UserCredential credential;
            var filepath = HostingEnvironment.MapPath("~/");
            var datafolder = HostingEnvironment.MapPath("/App_Data/MyGoogleStorage");
            using (var stream = new FileStream(filepath + "/App_Data/client_id.json", FileMode.Open, FileAccess.Read))
            {
                credential = await Google.Apis.Auth.OAuth2.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.YoutubeUpload, YouTubeService.Scope.Youtubepartner },
                    "user",
                    CancellationToken.None,
                    new FileDataStore(datafolder)
                );
            }


            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
            });

            var fileName = e.Name;

            guid = Path.GetFileNameWithoutExtension(fileName);

            var activityGetInfoUrl = ConfigurationManager.AppSettings["activityGetInfoUrl"];
            var activityUpdateInfoUrl = ConfigurationManager.AppSettings["activityUpdateInfoUrl"];

            activityGetInfoUrl = activityGetInfoUrl + "?guid=" + guid;
            var activityJsonResponse = new WebClient().DownloadString(activityGetInfoUrl);
            JObject activityJson = JObject.Parse(activityJsonResponse);

            var video = new Video();
            video.Snippet = new VideoSnippet();
            video.Snippet.Title = activityJson.GetValue("Title").ToString();
            video.Snippet.Description = activityJson.GetValue("Description").ToString();
            video.Snippet.Tags = new string[] { "#####", "######" };
            video.Snippet.CategoryId = "22"; // See https://developers.google.com/youtube/v3/docs/videoCategories/list
            video.Status = new VideoStatus();
            video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"

            using (var fileStream = new FileStream(e.FullPath, FileMode.Open))
            {
                var videosInsertRequest = youtubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");
                var videoStatus = videosInsertRequest.Upload();

                activityUpdateInfoUrl = activityUpdateInfoUrl + "?guid=" + guid + "&youtubeId=" + videosInsertRequest.ResponseBody.Id;
                new WebClient().DownloadString(activityUpdateInfoUrl);

                var newPlaylistItem = new PlaylistItem();
                newPlaylistItem.Snippet = new PlaylistItemSnippet();
                newPlaylistItem.Snippet.PlaylistId = ConfigurationManager.AppSettings["playlistId"];
                newPlaylistItem.Snippet.ResourceId = new ResourceId();
                newPlaylistItem.Snippet.ResourceId.Kind = "youtube#video";
                newPlaylistItem.Snippet.ResourceId.VideoId = videosInsertRequest.ResponseBody.Id;
                newPlaylistItem = await youtubeService.PlaylistItems.Insert(newPlaylistItem, "snippet").ExecuteAsync();
            }
        }
        catch(Exception ex)
        {
            log.Debug(ex.ToString());                
        }
  • 1
    Please take the [tour](http://stackoverflow.com/tour) and provide a [MCVE](http://stackoverflow.com/help/mcve). Based on what you report one can only guess what the problem is. – Daniel Mar 14 '17 at 11:05
  • Can you share a part of your code? – Ygalbel Mar 14 '17 at 11:19
  • @Daniel thank you for the information – user1664540 Mar 14 '17 at 12:25
  • @Ygalbel I have added code segment above – user1664540 Mar 14 '17 at 12:26
  • Thanks. Can you share exact line when exception is thrown? – Ygalbel Mar 14 '17 at 14:42
  • @Ygalbel I believe the problem wasn't caused by the code because it worked on morning on following day without single line of code or credential. I strongly believe it's caused by limitation Above mentioned exception coming in following line `var videoStatus = videosInsertRequest.Upload();` – user1664540 Mar 15 '17 at 04:51
  • It's a **quota** error. I found this [issue](https://github.com/google/google-api-dotnet-client/issues/480) in google api code. – Ygalbel Mar 15 '17 at 08:08
  • see [here](http://stackoverflow.com/questions/24736721/google-api-v3-videosinsertrequest-uploadasync-returns-response-status-code-doe) another question. – Ygalbel Mar 15 '17 at 08:09

0 Answers0