Uploading Video to Youtube with Asp .net MVC

0

I'm trying to do an integration with YouTube, but I'm getting the error

{"The remote server returned an error: (401) Unauthorized."}

I released my api key as the image below and I'm testing this code below, could someone help me by showing what is missing?

YouTubeRequestSettings settings = new YouTubeRequestSettings("VideoToYoutube", "AIzaSyBiXxL5nS6IjYRGJUhDdaYdWGqAGwOvD8A");

            YouTubeRequest request = new YouTubeRequest(settings);

            Video newVideo = new Video();

            newVideo.Title = "Teste";
            newVideo.Tags.Add(new MediaCategory("teste", YouTubeNameTable.CategorySchema));
            newVideo.Keywords = "Teste";
            newVideo.Description = "Teste";
            newVideo.YouTubeEntry.Private = false;
            newVideo.Tags.Add(new MediaCategory("teste, teste",
              YouTubeNameTable.DeveloperTagSchema));

            newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);


            newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\Users\tadriano\Documents\streaming\mov_bbb.mp4", "video/mp4");

            try
            {
                var createdVideo = request.Upload(newVideo);
            }
            catch (System.Exception ex)
            {
                var teste = ex.Message;
                throw;
            }


            return View();
        }

    
asked by anonymous 17.10.2015 / 21:12

1 answer

0

If someone needs a day I decided to change the login as below:

 public static Google.Apis.YouTube.v3.YouTubeService AuthenticateOaut(string clientId, string clientSecret, string userName)
        {

            string[] scopes = new string[] { Google.Apis.YouTube.v3.YouTubeService.Scope.Youtube,  // view and manage your YouTube account
                                             Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubeForceSsl,
                                             Google.Apis.YouTube.v3.YouTubeService.Scope.Youtubepartner,
                                             Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubepartnerChannelAudit,
                                             Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubeReadonly,
                                             Google.Apis.YouTube.v3.YouTubeService.Scope.YoutubeUpload};

            try
            {
                // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, ClientSecret = clientSecret }
                                                                                             , scopes
                                                                                             , userName
                                                                                             , CancellationToken.None
                                                                                             , new FileDataStore("Daimto.YouTube.Auth.Store")).Result;

                Google.Apis.YouTube.v3.YouTubeService service = new Google.Apis.YouTube.v3.YouTubeService(new Google.Apis.YouTube.v3.YouTubeService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Web client 1",

                });
                return service;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException);
                return null;

            }

        }

And in the console I created a key according to the image below:

    
18.10.2015 / 19:09