如何识别活动和直播协会?

时间:2015-08-27 10:36:21

标签: youtube-api youtube-livestreaming-api

我在youtube上创建了一个直播活动,并且我已将自定义提取(直播)与该直播活动相关联。

我可以通过调用

获取直播活动列表
https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&broadcastStatus=all

回复

{
 "kind": "youtube#liveBroadcastListResponse",
 "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/6LS8J5LIkMcXRAIUEViaRonO_jk\"",
 "items": [
  {

   "kind": "youtube#liveBroadcast",
   "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/eSW3gnAC5A4iNg4xj-r8vvP4ha8\"",
   "id": "M96Pswa174I",
   "snippet": {
    "publishedAt": "2015-08-27T09:26:52.000Z",
    "channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
    "title": "My new event",
    "description": "This is test event",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/vi/M96Pswa174I/default_live.jpg",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "https://i.ytimg.com/vi/M96Pswa174I/mqdefault_live.jpg",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "https://i.ytimg.com/vi/M96Pswa174I/hqdefault_live.jpg",
      "width": 480,
      "height": 360
     }
    },
    "scheduledStartTime": "2015-08-27T09:30:00.000Z",
    "isDefaultBroadcast": false
   }
  }
 ]
}

然后我可以通过调用

来获取直播
https://www.googleapis.com/youtube/v3/liveStreams?part=cdn%2Csnippet&mine=true

回复

- SHOW HEADERS -
{
 "kind": "youtube#liveStreamListResponse",
 "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/ctbzD5B9MI-wBMxDXCWCto2oFO8\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {

   "kind": "youtube#liveStream",
   "etag": "\"sGDdEsjSJ_SnACpEvVQ6MtTzkrI/LEFmnjMqvHydtqmxovlaXCai3vM\"",
   "id": "x_ZkmygOl4Bc0PHV8zXeag1440668944469033",
   "snippet": {
    "publishedAt": "2015-08-27T09:49:04.000Z",
    "channelId": "UCx_ZkmygOl4Bc0PHV8zXeag",
    "title": "My new stream",
    "description": "this is demo stream",
    "isDefaultStream": false
   },
   "cdn": {
    "format": "720p_hfr",
    "ingestionType": "rtmp",
    "ingestionInfo": {
     "streamName": "rathodm63.6584-jszu-8p4h-43yg",
     "ingestionAddress": "rtmp://a.rtmp.youtube.com/live2",
     "backupIngestionAddress": "rtmp://b.rtmp.youtube.com/live2?backup=1"
    }
   }
  }
 ]
}

但如何识别此蒸汽属于上述指定的直播事件?

1 个答案:

答案 0 :(得分:1)

You must use LiveBroadcasts.bind to bind a YouTube broadcast to a stream. Note that a broadcast can only be bound to one video stream, although a video stream may be bound to more than one broadcast. Then, you can use the LiveBroadcasts.list request and check the contentDetails.boundStreamId, which will be the stream associated with that livebroadcast. You'll have to specify part=contentDetails if you want to do this through an HTTP request.