Ohforf
Ohforf

Reputation: 3

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?

Upvotes: 0

Views: 6192

Answers (2)

JAL
JAL

Reputation: 42479

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}

Upvotes: 5

SLoN1ck
SLoN1ck

Reputation: 321

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

Upvotes: 1

Related Questions