0

I am trying to use YouTube Livestreaming API to get the health status of my live stream with partial success. It returns the following response when the stream is down and occasionally when the stream is up and doing fine. Why the search is returning an empty result when the streaming is fine? How to remove this ambiguity?

URL USED

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=[Channel ID]&eventType=live&type=video&key=[API KEY]

RESPONSE SAMPLE WHEN STREAM IS DOWN

{
  "kind": "youtube#searchListResponse",
  "etag": "vEIIB8AX6b5gvXSmMAHIm1mm2t8",
  "regionCode": "BR",
  "pageInfo": {
    "totalResults": 0,
    "resultsPerPage": 0
  },
  "items": []
}
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
ark1974
  • 615
  • 5
  • 16
  • I have experienced several issues with the [Search: list](https://developers.google.com/youtube/v3/docs/search/list) endpoint in the past. Maybe just using [Videos: list](https://developers.google.com/youtube/v3/docs/videos/list) may solve your problem as it seems you are just looking for `liveBroadcastContent` entry. – Benjamin Loison Aug 04 '22 at 11:49
  • @BenjaminLoison: Thanks a lot. Works when I use `id` filter, but the id changes with url when the stream restarts. I want to use channel_id which is fixed. I want to try `chart` filter in conjunction with videoCategoryId, any idea? – ark1974 Aug 05 '22 at 16:31
  • Then using [this answer](https://stackoverflow.com/a/27872244/7123660) checking whether or not most recent video is a live may do the trick. I don't get the point why you are mentioning "I want to try chart filter in conjunction with videoCategoryId, any idea?" – Benjamin Loison Aug 05 '22 at 18:32
  • @BenjaminLoison: `Videos:List` is a brilliant idea but the only downside is that I have to provide the video id which changes every time the stream restarts. – ark1974 Aug 06 '22 at 04:44
  • "but the only downside is that I have to provide the video id which changes every time the stream restarts" AFAIK there isn't official workaround without using the bugged and quota expensive Search: list endpoint. That's why I recommended you to retrieve the video id by "using [this answer](https://stackoverflow.com/a/27872244/7123660) checking whether or not most recent video is a live may do the trick." – Benjamin Loison Aug 06 '22 at 06:02
  • @BenjaminLoison: `Videos:list` solved my problem, huge thanks. But still I am unable to get the video-Id of my live stream using `Channel:list` or `Playlist:List` – ark1974 Aug 06 '22 at 17:27
  • May you precise what do you mean by "I am unable to get the video-Id of my live stream using `Channel:list` or `Playlist:List`" ? As I described "using [this answer](https://stackoverflow.com/a/27872244/7123660) checking whether or not most recent video is a live may do the trick." it seems clear to me how to proceed and if there is a problem, then please describe it precisely. – Benjamin Loison Aug 06 '22 at 19:07
  • The following links may also interest you https://www.youtube.com/channel/CHANNEL_ID/live and https://www.youtube.com/embed/live_stream?channel=CHANNEL_ID – Benjamin Loison Aug 07 '22 at 09:00
  • @BenjaminLoison: You can post this as answer , so that I can close the thread. – ark1974 Aug 10 '22 at 08:08
  • I posted it as an answer. – Benjamin Loison Aug 10 '22 at 08:27

1 Answers1

1

By fetching one of both following URLs you'll be able to distinguish whether or not the provided YouTube channel with channel id CHANNEL_ID is in live:

  1. https://www.youtube.com/channel/CHANNEL_ID/live
  2. https://www.youtube.com/embed/live_stream?channel=CHANNEL_ID

Or you can use Videos: list to know whether or not a given YouTube channel is livestreaming as you are just looking for liveBroadcastContent entry for the last uploaded video that you can retrieve using this answer.

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33