7

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.

Mahmoud Hanafy
  • 1,861
  • 3
  • 24
  • 33

3 Answers3

3

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
ynn
  • 3,386
  • 2
  • 19
  • 42
2

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")
Mahmoud Hanafy
  • 1,861
  • 3
  • 24
  • 33
0

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.

W. Reyna
  • 724
  • 2
  • 7
  • 24