You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用YouTube API channels.list无法获取谷歌账号下的品牌账号频道

解决谷歌账号关联YouTube频道全量获取问题

你当前代码只返回主频道「Earth」的核心原因是:mine=True参数仅会返回当前认证会话对应的单个频道(也就是你的主YouTube Studio频道),品牌账号关联的「Jupiter」「Mars」频道需要通过额外API调用获取。

以下是修正方案:

步骤说明

  • 先通过managedByMe=True参数获取当前账号管理的所有品牌账号对应的频道
  • 再将主频道(mine=True)和品牌频道的数据合并,得到全量关联频道

修改后的代码

SCOPE_CMD_MAPPER = {
    "upload": "https://www.googleapis.com/auth/youtube.upload",
    "readdata": "https://www.googleapis.com/auth/youtube.readonly",
    "search": "https://www.googleapis.com/auth/youtube.force-ssl",
    "update": "https://www.googleapis.com/auth/youtube.force-ssl",
    "resources": "https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtubepartner"
}

def get_all_associated_channels(client_secrets_file, youtube_access_file):
    youtube = get_authenticated_service("readdata", client_secrets_file)
    
    # 获取主频道(Earth)
    main_channel_request = youtube.channels().list(
        part="snippet,contentDetails,statistics",
        mine=True
    )
    main_channels = main_channel_request.execute().get("items", [])
    
    # 获取所有管理的品牌账号频道(Jupiter、Mars)
    brand_channels_request = youtube.channels().list(
        part="snippet,contentDetails,statistics",
        managedByMe=True
    )
    brand_channels = brand_channels_request.execute().get("items", [])
    
    # 合并所有频道数据
    all_channels = main_channels + brand_channels
    logger.info("get_all_associated_channels", "Youtube", f"{all_channels}")
    
    return all_channels

关键注意点

  • 确保你的谷歌账号确实是「Jupiter」「Mars」品牌账号的管理员,否则managedByMe=True不会返回对应频道
  • 权限范围保持youtube.readonly即可,无需额外调整

内容的提问来源于stack exchange,提问作者SrTan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 16:40:04