ark1974
ark1974

Reputation: 655

YouTube API to get the health status of live stream

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": []
}

Upvotes: 0

Views: 1590

Answers (1)

Benjamin Loison
Benjamin Loison

Reputation: 5612

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.

Upvotes: 1

Related Questions