Jigar
Jigar

Reputation: 3261

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?

Upvotes: 0

Views: 1089

Answers (2)

Kunal Awasthi
Kunal Awasthi

Reputation: 320

$.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

Upvotes: 1

mattferderer
mattferderer

Reputation: 974

You will need to use Oauth2 authentication for that API it appears.

https://developers.google.com/youtube/v3/live/registering_an_application

The page allows you to create two different types of credentials. However, all of the methods for the YouTube Live Streaming API require OAuth 2.0 authorization. Follow the instructions below to generate OAuth 2.0 credentials.

OAuth 2.0: Your application must send an OAuth 2.0 token with any request that accesses private user data. Your application sends a client ID and, possibly, a client secret to obtain a token. You can generate OAuth 2.0 credentials for web applications, service accounts, or installed applications.

See the Creating OAuth 2.0 credentials section for more information.

API keys: You have the option of including an API key with a request. The key identifies your project and provides API access, quota, and reports.

Note that all of the methods for the YouTube Live Streaming API require OAuth 2.0 authorization. For that reason, you need to follow the instructions above for generating OAuth 2.0 credentials. If you want, you can also send an API key, but it is not necessary.

Upvotes: 0

Related Questions