Search code examples
youtube-apiyoutube-data-apiyoutube-livestreaming-api

How do I use LiveBroadcasts:list from YouTube API?


I'm trying to use YouTube API for Live Broadcasts. But, I don't get any results. Here's what I do:

  1. Go to #Live YouTube channel:

    www youtube com channel / UC4R8DWoMoI7CAwX8_LjQHig
    
  2. Open any Live Broadcast to get Broadcast ID (for example, "CGt1Ac1gEZc").

  3. Try to use this Broadcast ID in irb:

    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. As you see, the @items array is empty.

  5. Open https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list to try to get data there, but still nothing (see image): https://i.sstatic.net/vl4Bx.png

Still, empty @items array. Even though this broadcast is 100% online, I tried filtering by "all" broadcasts, the result is the same: no items found.

Is this my fault or something happened to YouTube API?


Solution

  • That query is returning 0 items because the liveBroadcasts/list endpoint can only be used for broadcasts that the channel your are authenticated as has created. You cannot use the list endpoint to retrieve information about anyone else's broadcast.

    If you want to retrieve information on another channel's broadcast, you have to use the standard Search/list endpoint. This will return return only live events from a particular channel, without being authenticated as that channel/user, if you know that channel's channelId:

    part -> snippet

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

    eventType -> live

    type -> video (required when setting eventType to live)

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