YouTube API:如何获取liveChatId?

时间:2016-04-18 00:51:30

标签: youtube youtube-api youtube-livestreaming-api

文档说:

" liveChatId参数指定将返回其消息的聊天的ID。与广播相关联的实时聊天ID在liveBroadcast资源的snippet.liveChatId属性中返回。"

但是当使用API​​ Explorer和youtube.liveBroadcasts.list获取liveBroadcast的片段时,返回的结果上没有liveChatId属性。

我使用以下URI(键省略):

https://www.googleapis.com/youtube/v3/liveBroadcasts?part=snippet&mine=true

我做错了什么?

这是响应(某些值替换为......):

{
 "kind": "youtube#liveBroadcastListResponse",
 "etag": "...",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#liveBroadcast",
   "etag": "...",
   "id": "...",
   "snippet": {
    "publishedAt": "2016-04-18T17:04:24.000Z",
    "channelId": "...",
    "title": "...",
    "description": "...",
    "thumbnails": {
     "default": {
      "url": "...",
      "width": 120,
      "height": 90
     },
     "medium": {
      "url": "...",
      "width": 320,
      "height": 180
     },
     "high": {
      "url": "...",
      "width": 480,
      "height": 360
     },
     "standard": {
      "url": "...",
      "width": 640,
      "height": 480
     },
     "maxres": {
      "url": "...",
      "width": 1280,
      "height": 720
     }
    },
    "scheduledStartTime": "1970-01-01T00:00:00.000Z",
    "actualStartTime": "2016-04-18T17:04:24.250Z",
    "isDefaultBroadcast": false
   }
  }
 ]
}

在请求时,流上还会发生活动对话。

显然,使用"现在播放的直播广播"即使它们包含实时聊天,也不包含liveChatId。

有没有办法让#34;现在直播#34;直播?

3 个答案:

答案 0 :(得分:7)

这是一个相当古老的帖子,但看到我在互联网上搜索一个答案而找不到答案,我希望有人觉得这有用。

要获取的直播活动的liveChatId,您可以执行以下操作:

首先,获取videoId

response.items[0].id.videoId

然后获取liveStreamingDetails

buildApiRequest('GET',
        '/youtube/v3/videos', {
            'id': videoID,
            'part': 'snippet,contentDetails,statistics,liveStreamingDetails'
        });

现在您可以通过以下方式从上面的响应中获取liveChatId:

response.items[0].liveStreamingDetails.activeLiveChatId

答案 1 :(得分:1)

YouTube目前不支持将API调用与“Stream Now”混合并通过API创建事件。无法从“Stream Now”广播中获取聊天消息,只能通过API完全创建广播。

如果您认为这是API缺陷,我建议您打开增强或缺陷故障单here

答案 2 :(得分:0)

  

有没有办法让liveChatId用于“现在直播”直播?

是的,你可以。我有一个自动系统,只使用这个设置“Stream Now”流。

从我所看到的,我唯一不同的是,在API URI中指定broadcastType=allbroadcastType=persistent

你会注意到我的流是默认流,但是,它不一定是。实际上,LiveStream端点基本上唯一有用的方面是.status.configurationIssues信息。 (甚至streamName提取地址都不匹配)

这就是我将两个端点关联起来的方式。也许您可以使用此模板填写一些空白。 (所有字符串随机化并删除thumbnails部分)

LiveStreams

URI: https://www.googleapis.com/youtube/v3/liveStreams/?part=status,snippet&default=true 

回复:

{
    "kind": "youtube#liveStreamListResponse",
    "etag": "\"j1yhvAPYkjsoF8yjoVGsTlIFzCS/rqgpDvaMrWOPqUrLPxJd4XUFoKg\"",
    "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 5
    },
    "items": [
    {
        "kind": "youtube#liveStream",
        "etag": "\"j1yhvAPYkjsoF8yjoVGsTlIFzCS/SRutyOE9apA9K1qAdh2s9ZYE-Dp\"",
        "id": "e5LT2xEURi9BQzf2rLe5eB3325081929219850",  <-- liveBroadcasts .boundStreamId
        "snippet": {
            "publishedAt": "2016-09-05T23:21:33.000Z",
            "channelId": "QIr0IE1wRTRj2SUku4eFj0mK",
            "title": "Default Stream",
            "description": "",
            "isDefaultStream": true
        },
        "status": {
            "streamStatus": "active",
            "healthStatus": {
                "status": "good"
            }
        }
    }
    ]
}

<强> LiveBroadcasts:

URI: https://www.googleapis.com/youtube/v3/liveBroadcasts/?part=status,contentDetails,snippet,id&broadcastStatus=active&broadcastType=persistent

<强>响应:

{
    "kind": "youtube#liveBroadcastListResponse",
    "etag": "\"j1yhvAPYkjsoF8yjoVGsTlIFzCS/MFvQunCBDdqlkhPMness6LN1zao\"",
    "pageInfo": {
        "totalResults": 1,
        "resultsPerPage": 5
    },
    "items": [
    {
        "kind": "youtube#liveBroadcast",
        "etag": "\"j1yhvAPYkjsoF8yjoVGsTlIFzCS/mK_CAQ9rrVulNXbKbeIveFnQPd8\"",
        "id": "eXrevq9RzVQ",
        "snippet": {
            "publishedAt": "2017-05-07T16:58:05.000Z",
            "channelId": "QIr0IE1wRTRj2SUku4eFj0mK",
            "title": "514306-pgju",
            "description": "",
            "scheduledStartTime": "1970-01-01T00:00:00.000Z",
            "actualStartTime": "2017-05-08T01:21:45.000Z",
            "isDefaultBroadcast": true,
            "liveChatId": "NiHXTCKPfAyCJrPgREDRnvMSL0N5LBiVUlZoLSULA9vqyoR"
        },
        "status": {
            "lifeCycleStatus": "live",
            "privacyStatus": "unlisted",
            "recordingStatus": "recording"
        },
        "contentDetails": {
            "boundStreamId": "e5LT2xEURi9BQzf2rLe5eB3325081929219850", <-- LiveStreams .id
            "boundStreamLastUpdateTimeMs": "2016-09-05T23:21:33.749Z",
            "monitorStream": {
                "enableMonitorStream": false
            },
            "enableEmbed": true,
            "enableDvr": true,
            "enableContentEncryption": false,
            "startWithSlate": false,
            "recordFromStart": true,
            "enableClosedCaptions": false,
            "closedCaptionsType": "closedCaptionsDisabled",
            "enableLowLatency": false,
            "projection": "rectangular"
        }
    }
    ]
}

请注意,正如您在某种程度上注意到的那样,通过API处理“Stream Now”事件,而不仅仅是特定于liveChatId,有一些配置设置可以改变使用返回结果的方式默认参数,有时它们可​​以更改流程中涉及的顺序和步骤。我甚至发现实际上有一些参数适用于未记录的LiveStream端点,对LiveBroadcast端点也是如此。 另外有一些错误。