Reputation: 675
How can I get rtmp url and stream name for particular live event?
Previously I've been using Youtube API v.2.0 and could retrieve the list of live events which contained both rtmp urls and stream names. With the new Youtube Live Streaming API (v.3.0) I can retrieve the list of live events using liveBroadcasts
list method, but the response doesn't contain any rtmp urls and stream names. In order to get them I should create a new liveStream
resource or use an existing one.
Is there any way to get rtmp url and stream name without doing that?
Upvotes: 2
Views: 15559
Reputation: 1
function authenticate() {
return gapi.auth2.getAuthInstance()
.signIn({scope: "https://www.googleapis.com/auth/youtube.readonly"})
.then(function() { console.log("Sign-in successful"); },
function(err) { console.error("Error signing in", err); });
}
function loadClient() {
gapi.client.setApiKey("YOUR_API_KEY");
return gapi.client.load("https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest")
.then(function() { console.log("GAPI client loaded for API"); },
function(err) { console.error("Error loading GAPI client for API", err); });
}
// Make sure the client is loaded and sign-in is complete before calling this method.
function execute() {
return gapi.client.youtube.liveStreams.list({
"part": [
"snippet,cdn,contentDetails,status"
//"cdn"
],
"mine": true
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
var responseData = JSON.stringify(response);
alert(responseData);
//alert(response.result.items);
var itemsArr = response.result.items;
var itemObj = itemsArr[0];
alert('streamName = ' + itemObj.cdn.ingestionInfo.streamName);
//alert(responseData.result);
//var result = responseData.result;
},
function(err) { console.error("Execute error", err); });
}
gapi.load("client:auth2", function() {
gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
});
<script src="https://apis.google.com/js/api.js"></script>
<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>
Upvotes: 0
Reputation: 12877
You are right, you have to create liveStream. Broadcast is only the event object, whereas stream is your connection point. Here are some examples: https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/insert#examples
Upvotes: 3