Resolving two types of YouTube channel URLs in API v3

268 views Asked by At

I'm taking a youtube url as user input. The logic I have is as follows: if(URL === link_to_video) then get video else if( URL == link_to_channel) then get all_videos_of_channel.

I am doing this via JavaScript and using the YouTube API v3.

The problem is, it seems youtube has two types of URLs to youtube channels.

  • /channel/, eg: www.youtube.com/channel/UCaHNFIob5Ixv74f5on3lvIw
  • /user/, eg: www.youtube.com/user/CalvinHarrisVEVO

both the above links will take you to the same channel, but my current uploader code supports only /user/CalvinHarrisVEVO.

is there any way to make both the URLs behave similarly in terms of obtaining the channel videos?

1

There are 1 answers

1
mpgn On

One solution would be to parse the url and then apply this logic:

if there is `channel` in the url link
    call the APIv3 with the **id** of the channel
    Ressource : youtube.channels.list
else if there is 'user'
    call the APIv3 with the **forUsername** of the channel
    Ressource : youtube.channels.list

Check : https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list