Mahmoud Hanafy
Mahmoud Hanafy

Reputation: 1897

How to get youtube channel id using channel custom name?

My question is very similar to this one, I want to get channel id using channel custom name.

The answer on the question mentioned above which is:

GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=annacavalli&type=channel&key={YOUR_API_KEY}

doesn't work on small channels, for ex. when I run it with this channel: https://www.youtube.com/AnnaShearerfashionfettish it returns nothing.

Upvotes: 7

Views: 4103

Answers (3)

ynn
ynn

Reputation: 4815

It's very easy, using curl and grep.

Command

channel_name='DOVASYNDROMEYouTubeOfficial' #change this as you like
curl --silent "https://www.youtube.com/c/${channel_name}/videos" |\
    grep -o -P '(?<=canonical" href="https://www.youtube.com/channel/)[^"]*'

Output

UCq15_9MvmxT1r2-LLjtkokg

Upvotes: 3

Mahmoud Hanafy
Mahmoud Hanafy

Reputation: 1897

I didn't find a direct way to do this. I did a GET request to get the channel page HTML and parse it.

I used Jsoup to parse the html response.

val doc = Jsoup.parseBodyFragment(body)
val links = doc.select("link[rel=canonical]")
val channelUrl = links.first().attributes().get("href")

Upvotes: 2

W. Reyna
W. Reyna

Reputation: 724

Did you try

https://www.googleapis.com/youtube/v3/channels?part=snippetforUsername={username}&key={your key}

Remember to change {your key} to your API key, and {username} to the desired username.

Upvotes: 0

Related Questions