如何使用 YouTube API 中的 LiveBroadcasts:list?

How do I use LiveBroadcasts:list from YouTube API?

我正在尝试使用 YouTube API 进行直播。但是,我没有得到任何结果。这是我的做法:

  1. 转到#Live YouTube 频道:

    www youtube com channel / UC4R8DWoMoI7CAwX8_LjQHig
    
  2. 打开任意直播获取直播ID(例如"CGt1Ac1gEZc")。

  3. 尝试在 irb 中使用此广播 ID:

    irb(main):038:0> list = youtube.list_live_broadcasts("id,snippet,contentDetails,status", id: "CGt1Ac1gEZc")
    => #<Google::Apis::YoutubeV3::ListLiveBroadcastsResponse:0x0000000546a960 @etag="\"oqbvhYxBE6fAbRk6m7aLlHf5s1I/P7sEkFelJCqPWY-5t7EUKYER_MQ\"", @items=[], @kind="youtube#liveBroadcastListResponse", @page_info=#<Google::Apis::YoutubeV3::PageInfo:0x000000054634d0 @results_per_page=5, @total_results=0>>
    irb(main):039:0> list.items.inspect
    => "[]"
    
  4. 如您所见,@items 数组为空。

  5. 打开https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list to try to get data there, but still nothing (see image): http://i.imgur.com/6KTr1YS.png

仍然是空 @items 数组。 尽管这个广播是 100% 在线的,但我尝试按 "all" 个广播过滤,结果是一样的:找不到任何项目。

这是我的错还是 YouTube 出事了API?

该查询是 returning 0 项,因为 liveBroadcasts/list 端点只能用于您经过身份验证的频道所创建的广播。您不能使用 list 端点来检索有关其他任何人的广播的信息。

如果您想检索有关另一个频道广播的信息,您必须使用标准 Search/list 端点。如果您知道该频道的 channelId:

,这将 return return 仅直播来自特定频道的活动,而不会被验证为 channel/user

part -> snippet

channelId -> [channelId of the channel/user with the live event]

eventType -> live

type -> video(设置eventTypelive时需要)

HTTP GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={channelId}&eventType=live&type=video&key={YOUR_API_KEY}

要获取包含 (scheduledStartTime/activeLiveChatId) 的即将到来的流,您需要执行 liveStreamingDetails

https://www.googleapis.com/youtube/v3/search?part=id&channelId={YOUR_CHANNEL_ID}&eventType=upcoming&type=video&key={YOUR_API_KEY}

然后取出response.items[0].id.videoId用于

https://www.googleapis.com/youtube/v3/videos?part=liveStreamingDetails&id={VIDEO_ID}&key={YOUR_API_KEY}

我认为您也可以在第一个请求中使用 eventType=live 进行现场活动