如何查找特定频道的 forUsername 参数 [英] How to find the forUsername parameter for a specific channel

查看:41
本文介绍了如何查找特定频道的 forUsername 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm new to working with the YouTube API v3, and StacOverflow in general, so sorry for any mistakes.

现在我无法理解 forUsername 参数.对于某些频道,例如 YouTubeH2ODelerious,我可以找到正确的频道.当涉及到使用诸如 leagueoflegendsplayoverwatch 之类的频道时(当涉及到组成形式为 https:/的 URL 时,这两个都是频道的名称)/www.youtube.com/c/...) 我没有找到正确的频道,也没有找到任何频道,也没有找到没有观看次数或订阅者的频道.

Right now I am having trouble understanding the forUsername parameter. For some channels, such as YouTube or H2ODelerious, I am able to find the correct channel. When it comes to using channels such as leagueoflegends or playoverwatch (both of these being the names of the channels when it comes to composing a URL of form https://www.youtube.com/c/...) I do not find the correct channel and neither find no channel at all, nor one with no views or subscribers.

这是我的代码:

channelStats = testConnection.channels().list(
    part ='statistics',
    forUsername ='Youtube'
)
response = channelStats.execute()

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

If anyone knows whether there is another way to properly identify the correct channel while using the Channels.list method, please let me know. (Am using YouTube Data API v3 through Google's Client Library for Python and Python 3.8.)

推荐答案

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

I did answered thoroughly to precisely your kind of inquiry quite recently. I'd warmly recommend you to absorb these two posts:

  1. 如何从频道的用户名中获取包含西里尔字符的 YouTube 频道 ID

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

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

Here, I'll only emphasize that the forUsername request parameter has the following official specification:

forUsername (字符串)

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

The forUsername parameter specifies a YouTube username, thereby requesting the channel associated with that username.

但是,形式 URL 下的名称 NAME:

But, the name NAME under an URL of form:

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

不一定是相应 YouTube 频道的 YouTube 用户名.NAME 是该频道的自定义网址,一个不同的类别.

is not necessarily the YouTube username of the respective YouTube channel. NAME is that channel's custom URL, a different category.

根据 Google 员工在 2013 年 7 月 11 日发布的官方帖子不是每个频道都附加用户名的必要条件.Google 的问题跟踪器甚至会记录被拒绝的 forCustomUrl 功能请求暂时(至少对于 API 的 2020 年路线图).

According to an official Google staff post from 2013-07-11, it's not a requisite that every channel have attached an username. Google's issue tracker records even a forCustomUrl feature request that has been rejected for the time being (at least for the API's road map of 2020).

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

The second post I quoted above provides an algorithm that'll produce the channel ID associated to a given custom URL. Moreover, that post also provides a Python function that implements the algorithm.

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

A public (MIT licensed) Python 3 script -- youtube-search.py -- is linked to that post too; the script implements both the custom URL algorithm and the forUsername API querying.

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

This script produces the following outputs when invoked with each of the searched names your post above contains:

$ 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

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

Note that youtube-search.py requires a valid API key to be passed to it as argument of the command line option --app-key or, otherwise, passed on as the environment variable YOUTUBE_DATA_APP_KEY. (Use the command line option --help for brief helping info.)

另请注意,在通过以下方式调用搜索脚本的渠道中:

Also note that among the channels resulted from invoking the search script through:

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

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

only two have the customUrl property set, as follows:

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

$ python3 youtube-search.py --channel-url UCYd0SDTRQ54K1UQ-OkQd_7w
jehowen

这篇关于如何查找特定频道的 forUsername 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆