jsonrequestyoutube

Check if Channel is livestreaming in Youtube via Youtube API


Trying to check if a Youtube channel is currently livestreaming via a HTTP request to the YoutubeAPI. I used the request detailed at this post: How to check if YouTube channel is streaming live

I sent the following curl request: curl -X GET "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCLdl1fJeDXzdid6AmXE2YHg&eventType=live&type=video&key={API_KEY}"

As detailed in the previous stackoverflow post

And it returns this JSON:

{
  "kind": "youtube#searchListResponse",
  "etag": "9l4yMKnNWF8cwlGKh_JJCKYdIEI",
  "regionCode": "US",
  "pageInfo": {
    "totalResults": 0,
    "resultsPerPage": 0
  },
  "items": []
}

I understand that "items" returning an empty set means that the channel is not live, although in checking the channel through youtube, it is live. (Also I have double checked the channelID and it is the correct one). What am I doing wrong here?

Edit: I've tested it more and it only works for certain channels but not others. Is there an explanation for this?


Solution

  • For some reason, using the channel ID that you obtain from sending the following get request:

    curl -X GET "https://www.googleapis.com/youtube/v3/channels?part=id&forUsername={USERNAME}&key={API_KEY}" does not work when trying to find an active live broadcast for the channel.

    Instead, I stumbled upon a roundabout way by using the "q=" parameter, which essentially searches for any YouTube video that contains the string in the "q=" parameter, to find the live stream via the name of the video live stream itself.

    This is when I found out that the ChannelID that gets returned by this request is different from the ChannelID I got from the request above.

    Using this channel ID I was able to get the video ID of a youtube live stream assuming that the channel was live.