Upload Video to Youtube with Asp . net MVC

Asked

Viewed 108 times

0

I’m trying to make an integration with Youtube, but I’m getting the error

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

I released my key api as per the image below and I am testing this code below, someone could help me 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();
        }

inserir a descrição da imagem aqui

  • In HTTP referrers, it is not necessary to put the URL where this calling?

  • I put localhost, localhost, 127.0.0.1 and nothing... so I left it blank for this last test.

1 answer

0

If anyone needs one 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 as image below: inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.