如何查找特定频道的 forUsername 参数

1 python youtube-api youtube-data-api

我刚开始使用 YouTube API v3 和 StacOverflow,对于任何错误,我深表歉意。

现在我无法理解该forUsername参数。对于某些频道,例如YouTubeH2ODelerious,我能够找到正确的频道。当涉及到使用诸如leagueoflegendsplayoverwatch之类的频道时(这两个频道都是在编写表单 URL 时的频道名称https://www.youtube.com/c/...),我找不到正确的频道,也没有找到任何频道,也没有找到没有频道的频道。浏览量或订阅者。

这是我的代码:

channelStats = testConnection.channels().list(
    part ='statistics',
    forUsername ='Youtube'
)
response = channelStats.execute()
Run Code Online (Sandbox Code Playgroud)

如果有人知道在使用该方法时是否有其他方法可以正确识别正确的通道Channels.list,请告诉我。(我通过 Google 的 Python 和 Python 3.8 客户端库使用 YouTube Data API v3。)

stv*_*var 5

我最近确实彻底回答了您的询问。我强烈建议您阅读这两篇文章:

  1. 如何从频道用户名(包括西里尔字母

  2. 从 youtube.com/c/xxxx 链接获取频道 ID?

这里我只强调一下,请求forUsername参数官方规范如下:

for用户名(字符串)

forUsername参数指定 YouTube 用户名,从而请求与该用户名关联的频道。

但是,URL 下的名称NAME格式为:

https://www.youtube.com/c/NAME

不一定是相应 YouTube 频道的 YouTube 用户名。NAME是该频道的自定义 URL,不同的类别。

根据谷歌官方2013年7月11日发布的帖子,并不是每个频道都必须附上用户名。Google 的问题跟踪器甚至会记录 暂时被拒绝的forCustomUrl功能请求(至少对于 API 的 2020 年路线图而言)。

我上面引用的第二篇文章提供了一种算法,可以生成与给定自定义 URL 关联的通道 ID。此外,该帖子还提供了实现该算法的Python函数。

公共(MIT 许可)Python 3 脚本 -- youtube-search.py-- 也链接到该帖子;该脚本实现了自定义 URL 算法和forUsernameAPI 查询。

当使用上面帖子中包含的每个搜索名称调用时,该脚本会产生以下输出:

$ python3 youtube-search.py --user-name YouTube
UCBR8-60-B28hp2BmDPdntcQ

$ python3 youtube-search.py --custom-url YouTube
youtube-search.py: error: custom URL "YouTube": no associated channel found

$ python3 youtube-search.py --user-name H2ODelerious
youtube-search.py: error: user name "H2ODelerious": no associated channel found

$ python3 youtube-search.py --custom-url H2ODelerious
youtube-search.py: error: custom URL "H2ODelerious": no associated channel found

$ python3 youtube-search.py --search-term H2ODelerious --type=channel
UCClNRixXlagwAd--5MwJKCw: H2ODelirious
UCagP0Z1PVAAOpYV4HKy6w9w: H2o Delerious
UC6x4XQ6cqBzxGlSlCwcyUBw: H2O Delerious
UCzOeqwelmnbBDf3bIHde0EQ: H2O Delerious
UCLmpVRE4XIEem_1EwHxqtXQ: H2O Delerious plays
UCxxWGzT90DG1gk2pnvcRt2w: h2o delerious fan artist
UCYH7TzSISrC-2Mfy3TyjUDQ: H2O DELERIOUS Flores
UCfRjtX1qzFbCptULo529HsA: Jbz2swag
UCYd0SDTRQ54K1UQ-OkQd_7w: Jehowen
UCjozfwXXP7bEGPDFpAtgsYQ: LittleCool Me

$ python3 youtube-search.py --user-name leagueoflegends
UCvewcgPDiYrVNiyh8kpOnFQ

$ python3 youtube-search.py --custom-url leagueoflegends
UC2t5bjwHdUX4vM2g8TRDq5g

$ python3 youtube-search.py --user-name playoverwatch
UCM9KGdihR14QHFeyOsA-kgA

$ python3 youtube-search.py --custom-url playoverwatch
UClOf1XXinvZsy4wKPAkro2A
Run Code Online (Sandbox Code Playgroud)

请注意,youtube-search.py需要将有效的 API 密钥作为命令行选项的参数传递给它--app-key,否则作为环境变量传递YOUTUBE_DATA_APP_KEY。(使用命令行选项--help获取简短的帮助信息。)

另请注意,其中的频道是通过以下方式调用搜索脚本产生的:

$ python3 youtube-search.py --search-term H2ODelerious --type channel,

只有两个customUrl设置了属性,如下:

$ python3 youtube-search.py --channel-url UCClNRixXlagwAd--5MwJKCw
h2odelirious

$ python3 youtube-search.py --channel-url UCYd0SDTRQ54K1UQ-OkQd_7w
jehowen
Run Code Online (Sandbox Code Playgroud)