我的问题与这个链接非常相似,我想通过频道自定义名称获取频道ID。
上述问题的答案是:
GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=annacavalli&type=channel&key={YOUR_API_KEY}
在小渠道上无法使用,例如当我运行它时,使用此渠道:https://www.youtube.com/AnnaShearerfashionfettish,它会返回空白。
我的问题与这个链接非常相似,我想通过频道自定义名称获取频道ID。
上述问题的答案是:
GET https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=annacavalli&type=channel&key={YOUR_API_KEY}
在小渠道上无法使用,例如当我运行它时,使用此渠道:https://www.youtube.com/AnnaShearerfashionfettish,它会返回空白。
curl
和grep
即可。
命令:
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/)[^"]*'
输出
UCq15_9MvmxT1r2-LLjtkokg
我没有找到直接的方法来做这件事。我发送了一个GET请求来获取频道页面的HTML并解析它。
我使用Jsoup解析html响应。
val doc = Jsoup.parseBodyFragment(body)
val links = doc.select("link[rel=canonical]")
val channelUrl = links.first().attributes().get("href")
你尝试过吗?
https://www.googleapis.com/youtube/v3/channels?part=snippetforUsername={username}&key={your key}
记得将{your key}
更改为你的API密钥,并将{username}
更改为所需的用户名。