Play private videos with Youtube API

Good afternoon people, I'm trying to make an integration with the YouTube API, where the videos can be played by an iframe on my page, which by the way is in ASP.NET. the documentation indicated me this code.

<!DOCTYPE html>
<html>
  <body>
    <!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
    <div id="player"></div>

    <script>
      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');

      tag.src = "https://www.youtube.com/iframe_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
          height: '360',
          width: '640',
          videoId: 'M7lc1UVf-VE',
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
          }
        });
      }

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.playVideo();
      }

      // 5. The API calls this function when the player's state changes.
      //    The function indicates that when playing a video (state=1),
      //    the player should play for six seconds and then stop.
      var done = false;
      function onPlayerStateChange(event) {
        if (event.data == YT.PlayerState.PLAYING && !done) {
          setTimeout(stopVideo, 6000);
          done = true;
        }
      }
      function stopVideo() {
        player.stopVideo();
      }
    </script>
  </body>
</html>

So far everything is fine, I managed to use it correctly, but I would like to know how to do it in case of private videos ? Is there a way to send an authentication to the API that identifies me as the account holder where the video was uploaded ? Thank you!

Author: Gabriel Bastos, 2019-05-24

1 answers

With private i believe it is impossible, what you can/should use is the unlisted

To change privacy do the following steps:

  1. log in to the beta version of YouTube Studio.
  2. from the left-hand menu, select videos.
  3. hover over the video you want to update. Select the tab
  4. live to see your uploads live.
  5. click the pencil icon under visibility and choose Público, Privado or Não listado (in your case the latter)

More details at: https://support.google.com/youtube/answer/157177?hl=pt

 2
Author: Guilherme Nascimento, 2019-05-24 21:42:35