Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using YouTube API, how to get the video id for a live stream from the channel name?

There are 3 ways that i can access a stream from a channel /live:

  • https://youtube.com/channel/channel_id/live
  • https://youtube.com/user/username/live
  • https://youtube.com/c/channel_name/live

I know how to get it from the channel_id and i know how to get the channel_id from the username. My problem is on the 3rd case. Is it possible to get the channel_id from this custom URL?

Second question. The way i get the video URL from the channel id is using the following endpoint:

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

I've notice that if the channel has a live stream going on at /channel-id/live and have other stream on with specific URL I have no warranty that the video URL that i get is the one associated with the /channel-id/live. Is that a way to get this specific video?

like image 574
Rafael Reis Avatar asked Nov 08 '22 15:11

Rafael Reis


1 Answers

I know this post is pretty old but I recently faced this issue as well and was able to find an answer from this SO post.

Basically, take the CHANNEL_ID and utilize YouTube's Search endpoint like this:

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

This request will return a youtube#video object that contains the videoId

like image 131
Zac Clark Avatar answered Nov 30 '22 19:11

Zac Clark