Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using YouTube API v3 to tell if a channel has a live stream

Tags:

youtube-api

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!

like image 874
ScoWalt Avatar asked Mar 10 '14 20:03

ScoWalt


People also ask

How do you tell if a YouTube channel is live?

How to Know When a Channel Is Live Streaming on YouTube. If you come across a channel that has a red ring around it with the word "live" while scrolling through your feed on your phone, that's how you know that channel is currently live.


3 Answers

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.

like image 103
George Donev Avatar answered Oct 16 '22 15:10

George Donev


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.

like image 34
Konstantin Victoria Avatar answered Oct 16 '22 15:10

Konstantin Victoria


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

like image 20
Gitago Avatar answered Oct 16 '22 16:10

Gitago