Reputation: 1897
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
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
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
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