0

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.stack.imgur.com/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?

JAL
  • 41,701
  • 23
  • 172
  • 300
Ohforf
  • 3
  • 1
  • 3

2 Answers2

5

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}
Tsquare
  • 21
  • 6
JAL
  • 41,701
  • 23
  • 172
  • 300
  • Thank you! Though, it doesn't provide the liveChatId, which is crucial for my main goal: I want to get messages from the Chat of the Live Broadcast channel. So ,the next question is: can I use the `liveChatMessages/list` endpoint to retrieve the messages from NOT my broadcast chat? – Ohforf Jan 11 '16 at 16:28
  • @Ohforf there is currently no API exposed for retrieving chat messages on another channel's broadcast. For related discussion, and the API to retrieve chat messages from **your own broadcasts**, see this question: http://stackoverflow.com/q/26229728/2415822 – JAL Jan 11 '16 at 16:58
  • OK, great. Thank you very much! – Ohforf Jan 11 '16 at 18:23
  • I wanted something similar for getting the uptime of a stream. Seems it's not possible only using `search`. – Jacob Morrison Jul 24 '18 at 01:31
  • Aww that's great, Its a big relief. Google has been ruining my time with https://developers.google.com/youtube/v3/live/getting-started – Sami Feb 25 '21 at 06:46
0

For getting liveStreamingDetails that contains (scheduledStartTime/activeLiveChatId) for upcoming streams you'd need to perform

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

And then take out response.items[0].id.videoId and use it for

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

I think you can do for live events as well with eventType=live in the first request

SLoN1ck
  • 271
  • 3
  • 6