How to get stream name/key of YouTube Live “Stream

2019-01-28 18:49发布

问题:

YouTube added "Stream now (beta)" service last July which makes live streaming much easier.

Using Youtube verified programs like "XSplit Broadcaster" you can stream to "Stream now" after authorization.

I'm also doing a streaming application and what I'm looking for is the API to get the stream name of the default "Stream now" stream. With the stream name I can stream content to YouTube.

YouTube documentation https://developers.google.com/youtube/v3/live/docs/ doesn't mention anything about it, and the default broadcast is not included in the result of youtube.liveBroadcasts.list.

If XSplit Broadcaster can do it, I think there must have an API for it. Anyone knows it?

==================================== Update:

Form the documentation here https://developers.google.com/youtube/v3/live/docs/liveBroadcasts there should be a isDefault field in a Broadcast (snippet.isDefaultBroadcast). And there should be a default broadcast and default live stream.

But when I ran livebroadcasts.list to get all broadcasts, I got

{
 "kind": "youtube#liveBroadcastListResponse",
 "etag": "\"abQHWywil_AkNqdqji7_FqiK-u4/z2Ncj_KliOCAGV1jEVPYCsHbZn0\"",
 "pageInfo": {
  "totalResults": 4,
  "resultsPerPage": 50
 },
 "items": [
 ]
}

Although the totalResults = 4, there's nothing in returned items.

回答1:

Solved, the default broadcast can be retrieved by setting broadcastType to "persistent" in livebrocasts.list.

GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=+id%2C+snippet%2C+contentDetails%2C+status&broadcastType=persistent&mine=true&key={YOUR_API_KEY}

And default stream can be retrieved by livestreams.list with boundstreamid.