Search code examples
ajaxyoutube-apiyoutube-data-apilive-streaming

I want to show youtube channel live broadcast on my own website with YouTube Data API v3


I have one website in pure HTML where I want to show YouTube live broadcast from my channel when I am live on YouTube.

$.ajax({
    url: "https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2C+snippet%2C+contentDetails&broadcastType=all&mine=true&key={my-key}",
    type: "GET",
    success: function (result) {
        console.log(result);
    }
});

when I am using above code it's showing me login required.

Is there any way I can show my channel live video without login?


Solution

  • $.ajax({
        type: "GET",
        url: "https://www.googleapis.com/youtube/v3/search?part=id,snippet&eventType=completed&channelId={YOUR-CHANNEL-ID}&type=video&key={YOUR-API-KEY}",
       
        async:true,
        crossDomain:true,
        dataType : 'JSON',
        success: function(data){
    		$.each(data.items,
                function(i,item)
                { 
    				var app = 
    				'<div>\
    							<iframe src="https://www.youtube.com/embed/'+item.id.videoId+'" width="100%" height="auto" allowfullscreen></iframe>\
    						</div>';
                    $('.container').append(app);
            }); 
        }
      });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="container">
     
    </div>
    i found a work around without OAUTH2.0 using API KEY and channel-ID using search API of YT DATA API. you can change the eventType to live and completed. items.snippet.id.videoId for video id and items.snippet.title for title of video. Read documentation https://developers.google.com/youtube/v3/docs/search/list