2016-04-18 50 views
3

該文檔說:YouTube API:如何獲取liveChatId?

「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,即使它們包含實時聊天。

有沒有辦法讓liveChatId進行「Stream Now」直播?

+0

你可以發佈你從YouTube獲得的樣本回復嗎?你確定你正在列出一個已經開始的事件並且有一個有效的聊天室/ ID嗎? – JAL

+0

用請求的信息更新了帖子。實時廣播是流式傳輸,聊天室在請求時處於活動狀態。如果我不是流媒體,那麼正如預期的那樣,響應中沒有任何項目。 –

+0

你在說liveBroadcast的liveChatId或用戶的liveChatId(禁止或刪除)嗎? – noogui

回答

1

YouTube目前不支持將API調用與「Stream Now」混合並通過API創建事件。沒有辦法從「Stream Now」廣播中獲取聊天消息,只能使用API​​完全創建廣播。

如果您認爲這是一個API缺陷,我建議您打開一個增強或缺陷標籤here

+1

這不完全正確。您可以手動創建實時事件並從該流獲取聊天消息。但你對「現在直播」是正確的。謝謝。 :) –

+0

@ C.Olimar:可以確認手動創建事件是否有效。謝謝:) –

+0

@AvindraGoolcharan你可以提供代碼提示如何做到這一點? – KMX

0

有沒有辦法讓liveChatId的「現在直播」直播?

是的,你可以。我有一個自動化系統,只使用這個設置「Stream Now」流。

從我所看到的唯一不同的事情我可以在API URI中指定broadcastType=allbroadcastType=persistent

你會注意到我的流是默認流,但它不一定是。實際上,LiveStream端點基本上唯一有用的方面是.status.configurationIssues信息。 (甚至沒有streamName攝取地址匹配)

這是我如何關聯兩個端點。也許你可以使用這個模板來填充一些空白。(所有字符串的隨機和thumbnails部分移除)

串流

 
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處理 「現在流」 事件,而不僅僅是特定於liveChatId,有一些配置設置可以更改使用默認參數返回結果的方式,有時它們可​​以更改過程中涉及的順序和步驟。我甚至發現實際上有幾個參數與LiveStream端點一起工作,沒有記錄,對於LiveBroadcast端點也是如此。 此外還有一些錯誤。

2

這是一個相當老的帖子,但是當我在互聯網上搜索了一個答案並找不到一個答案時,我希望有人認爲這有幫助。

要獲得是你可以做一些類似以下的直播活動的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 
相關問題