您必须承认 YouTube 网站的以下特性:它允许(根据设计)同名(在您的情况下为 Markiplier)作为频道的自定义 URL,同时,另一个频道的(旧)用户名。
请阅读first few paragraphs of my answer 到一个非常相关的问题。从那里,您将对以下两个(有时令人困惑的)概念之间的区别有一个很好的了解:频道用户名和频道自定义 URL。
具体来说,如果您使用我的 Python3 公共脚本youtube-search.py,您会看到有两个不同的渠道表现出我刚刚描述的 w.r.t. 行为。名字Markiplier:
$ python3 youtube-search.py --user-name Markiplier
UCxubOASK0482qC5psq89MsQ
$ python3 youtube-search.py --custom-url Markiplier
UC7_YxT-KID8kRbqZo7MyscQ
请注意,youtube-search.py 需要将有效的 API 密钥作为命令行选项 --app-key 的参数传递给它,否则,作为环境变量 YOUTUBE_DATA_APP_KEY 传递给它。 (使用命令行选项--help 获取简要帮助信息。)
对以下 URL 的进一步 Channels.list API 端点查询:
https://www.googleapis.com/youtube/v3/channels?id=UCxubOASK0482qC5psq89MsQ,UC7_YxT-KID8kRbqZo7MyscQ&part=id,snippet,statistics&fields=items(id,snippet(title,description,customUrl),statistics(subscriberCount))&maxResults=2&key=...
将确认您所经历的差异:
{
"items": [
{
"id": "UCxubOASK0482qC5psq89MsQ",
"snippet": {
"title": "markiplier",
"description": "I will no longer be updating this channel! All my new videos with be uploaded to markiplierGAME! Please re-subscribe on that channel to stay up-to-date on my videos!"
},
"statistics": {
"subscriberCount": "85000"
}
},
{
"id": "UC7_YxT-KID8kRbqZo7MyscQ",
"snippet": {
"title": "Markiplier",
"description": "Welcome to Markiplier! Here you'll find some hilarious gaming videos, original comedy sketches, animated parodies, and other bits of entertainment! If this sounds like your kind of channel then please Subscribe Today!\n\nTotal Charity Raised ▶ $3,000,000+",
"customUrl": "markiplier"
},
"statistics": {
"subscriberCount": "27800000"
}
}
]
}
现在,总结一下我的观点。你的问题——我遇到了同名频道的不幸问题。我该如何防止这种情况发生? --,我注意到以下几点:
- 确定您希望从 API 获得什么:自定义 URL 和 用户名 是不同的 API 概念。
- 如果您尝试获取有关您拥有其用户名的频道的信息,请使用
Channel.list 端点和适当的forUsername 参数进行查询。
- 如果您尝试获取有关给定 自定义 URL 频道的信息,请使用我在回答此问题 Obtaining a channel id from a youtube.com/c/xxxx link 中描述的过程和 Python 代码。还要为该过程可能失败做好准备(由于 API 当前的实施方式,该过程很可能在某些有效的自定义 URL 上失败)。