18

The goal of my YouTube API call is, given a channelId, to return whether that channel is currently live streaming. This is the call I'm making currently:

https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&eventType=live&type=video&key={YOUR_API_KEY}

While this call is functional, there is a significant delay between the channel starting a live stream and this call returning the stream.

Is there a better call to use in the YouTube v3 API that doesn't require oAuth? The functionality of my app is read-only.

Thanks!

ScoWalt
  • 411
  • 3
  • 8
  • 10
  • 1
    Does this answer your question? [How to check if YouTube channel is streaming live](https://stackoverflow.com/questions/32454238/how-to-check-if-youtube-channel-is-streaming-live) – Michael Jun 16 '20 at 15:03

3 Answers3

3

Probably late but still someone else would use it, i found the answer on google api docs:

https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list (Scroll to bottom, you can use their onsite api to make calls on the fly)

The call you have to make is:

GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2Cstatus&mine=true&broadcastStatus=active&key={YOUR_API_KEY}

(atm, they have an issue wth the status field). You can remove the filter and check the returned results for

{ "status": { "lifeCycleStatus": "live"}}

And as per google docs:

Before you start

You need a Google Account to access the Google Developers Console, request an >API key, and register your application. Register your application with Google so that it can submit API requests. After registering your application, select the YouTube Data API as one of the >services that your application uses:

Go to the Developers Console and select the project that you just registered. Open the API Library in the Google Developers Console. If prompted, select a >project or create a new one. In the list of APIs, make sure the status is ON for >the YouTube Data API v3 and, if you are a YouTube Content Partner, the YouTube >Content ID API.

Calling the Data API

The API request must be authorized by the Google Account that owns the >broadcasting YouTube channel.

You can check this link for generating an access(OAuth 2.0) token: https://developers.google.com/identity/protocols/OAuth2?hl=en

I hope this helps.

Community
  • 1
  • 1
George Donev
  • 563
  • 7
  • 13
  • 1
    I am trying to use this, but I get a 401 Login Required error, any ideas? – HeroCC Aug 20 '15 at 20:18
  • 4
    Found out why, as of this comment YouTube requires OAUTH for anything interacting with the liveBroadcast part of the API. This answer no longer works because it uses an API key rather than Oauth – HeroCC Aug 24 '15 at 15:02
  • 4
    I've un-accepted this answer since it now requires OAUTH, and my original question was about a request that doesn't require OAUTH. – ScoWalt Sep 02 '15 at 21:16
  • 8
    The `mine=true` bit is another fly in the ointment. It tells you whether your own channel has any live broadcasts. It doesn't let you query about another person's channel. Useful if you're writing an OBS plugin, useless if you're writing a widget to notify about people you're following going live. – dhasenan Oct 15 '16 at 23:55
  • @ScoWalt dos this answer do what you are after? https://stackoverflow.com/a/32463253/43465 – Daniel Jan 19 '18 at 07:03
  • 1
    @Daniel, looks like that question is a duplicate of mine. That answer will probably work! (the `eventType=live` part of the request URL is key, and it may not have been around in 2014 when I asked this!) – ScoWalt Feb 08 '18 at 22:32
  • @HeroCC where did you get information about `liveBroadcast` should use OAuth? There is no information in docs – kicaj Feb 22 '18 at 11:35
  • @kicaj I'm not sure exactly how I found out (as I last did this a few years ago) but I think that I just tried to implement it and failed. I ended up making a request to the search api and just using a normal API key as OP did. – HeroCC Feb 23 '18 at 02:54
2

The /search call is rather expensive. If you are only allotted the initial 10k quota points, you'd run out of points after only 100 queries. That may not be a bother for some use cases, but it is nevertheless limited.

Instead, you can use Playwright and do the following:

page.goto("https://YouTube.com/channel/{channel id}/live")

Then check for a redirection which will happen when the channel is live:

const redirect = page.url()

If redirect contains a link to a YouTube video, then you know the channel is live. Otherwise it is not live and will yield a link similar to the one that's passed in to the goto() function.

Michael
  • 8,362
  • 6
  • 61
  • 88
2

I was digging for a "cheaper" way to find if a channel is live to save some API quota. I attempted to use Konstantin's workaround by looking at the {channel/channel_id}/live but this appears to not work anymore.

The channel no longer redirects when a person is live. Instead it runs on that page.

  • If they have a username URL then /c/ works: https://www.youtube.com/c/USER_NAME/live

  • If they have don't have a username and use the default like UC4R8DWoMoI7CAwX8_LjQHig, then you need to use https://www.youtube.com/channel/USER_NAME/live

Michael
  • 8,362
  • 6
  • 61
  • 88
Gitago
  • 41
  • 3