Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ChannelID from Youtube Custom URL

Is there any way that I can get the channel ID of a Youtube Channel by having its custom url (using the Youtube API) ?

Example:

A custom url is like:

https://www.youtube.com/onepiece

I want to get its channelID, so that I have the link like:

www.youtube.com/user/OnePieceUK

like image 231
Nuno Pereira Avatar asked Sep 25 '17 13:09

Nuno Pereira


2 Answers

Elaborating on this answer of mine, I'll note here the following facts:

  1. In YouTube URLs of form https://www.youtube.com/c/NAME or https://www.youtube.com/NAME, NAME is a channel's custom URL. (See this official account from Google support.)

  2. In YouTube URLs of form https://www.youtube.com/user/NAME, NAME is a channel's user name. User names are a legacy feature of the API v3; not every channel has one attached; no channel is required to have one attached. (See this official statement from Google staff from 2013-07-11.)

The two API concepts -- custom URLs and user names -- encompass two different categories.

The public (MIT licensed) Python 3 script youtube-search.py referred by my answer quoted above is able to search the API for custom URLs and respectively query the API for user names:

$ python3 youtube-search.py --custom-url onepiece
UC6LPb3zSebrzU_0Yclpwb4Q

$ python3 youtube-search.py --user-name OnePieceUK
UC6LPb3zSebrzU_0Yclpwb4Q

Note that youtube-search.py requires a valid API key to be passed to it as argument of the command line option --app-key or, otherwise, passed on as the environment variable YOUTUBE_DATA_APP_KEY. (Use the command line option --help for brief helping info.)

like image 85
stvar Avatar answered Oct 11 '22 12:10

stvar


I recently had a similar requirement where I knew the custom URL of a youtube channel and I want to get the channel id. So I went to the YouTube channel and clicked on a random video to get the Video ID from the web browser url. Once I get the Video Id, then I used the "Videos: list" API to get the video details:

https://youtube.googleapis.com/youtube/v3/videos?part=snippet&id=[VEDIO_ID]&key=[YOUR_API_KEY]

The retuned data contained all the metadata information about the video, including ChannelId :-).

It may not be the most smartest and elegant way of doing things, but it solved my purpose.

like image 24
Saptadip Sarkar Avatar answered Oct 11 '22 12:10

Saptadip Sarkar