【问题标题】:Get the current liveBroadcast name for my channel's "Stream Now" stream via YouTube Live Streaming API通过 YouTube Live Streaming API 获取我频道的“立即直播”流的当前直播名称
【发布时间】:2020-01-10 15:30:21
【问题描述】:
我们开始使用 YouTube 的 Stream Now 功能,并注意到虽然该功能具有静态 YouTube URL(即:YouTube.com/channel-name/live),但广播/视频 ID 会在新流结束时发生变化,并且一个新的开始。
有没有一种方法可以通过 YouTube API 了解我的频道流的当前直播/视频 ID(通过 Stream Now 功能)?
当我们这样做的时候,有没有办法让 Stream Now 中的这个广播名称不会改变并且始终保持不变?这将允许为所有流重用相同的嵌入代码。
谢谢!
【问题讨论】:
标签:
youtube-api
youtube-livestreaming-api
【解决方案1】:
您可以通过在对 liveBroadcast/list 的请求中将 broadcastType 设置为 persistent 来检索“Stream Now”广播。
GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2C%20status%2C%20contentDetails&broadcastStatus=all&broadcastType=persistent&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
但是在“立即直播”流结束后,广播将转换为视频,您必须创建一个新的直播。它没有记录,但我发现你可以通过调用 liveBroadcast/insert 来做到这一点,只有 "isDefaultBroadcast" 参数设置为 true
POST https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2C%20status%2C%20contentDetails&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json
{
"snippet": {
"isDefaultBroadcast": true
}
}
希望对你有所帮助,我花了很多时间才找到这个,因为 Youtube Live API 的文档不好......