5

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,751
  • 2
  • 23
  • 31
  • Possible duplicate of [How to get Youtube channel details using Youtube data API if channel has custom url](https://stackoverflow.com/questions/37267324/how-to-get-youtube-channel-details-using-youtube-data-api-if-channel-has-custom) – DaImTo Nov 03 '17 at 14:02
  • as you can see, I've already mentioned in the question that it is very similar to this question, but the answer there doesn't work with me. So I asked this question. – Mahmoud Hanafy Nov 03 '17 at 15:02
  • then you should ask for clarification on the existing question not open a second question – DaImTo Nov 03 '17 at 15:03
  • https://stackoverflow.com/help/duplicates – DaImTo Nov 03 '17 at 15:04
  • I asked for clarification at the answer there, but how can I like reshow this question to be able to get an answer for my case? – Mahmoud Hanafy Nov 03 '17 at 15:05

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
  • 2,345
  • 14
  • 31
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,751
  • 2
  • 23
  • 31
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
  • 664
  • 1
  • 7
  • 20