YouTube API - 使用 Google 管理员帐户访问多个 youtube 频道(品牌帐户) [英] YouTube APIs - Access mutiple youtube channels (Brand Accounts) using Google Admin account

查看:12
本文介绍了YouTube API - 使用 Google 管理员帐户访问多个 youtube 频道(品牌帐户)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 YouTube 分析和报告 API 从视频中提取信息.

I need to extract information from videos using YouTube Analytics and Reporting Api.

当我使用我的 Google 帐户登录 YouTube 时,我可以访问多个 YouTube 品牌帐户.

I have access to multiple YouTube Brand Accounts, when I log into YouTube with my Google Account.

使用试用"来测试 API,我只能在切换到该频道所属的品牌帐户后检索该频道的数据,否则我会收到 403 - Forbidden 错误.

Using the "Try it" for testing the API, I'm only able to retrieve data for a channel once I switch to the Brand Account that this channel belongs, otherwise I get 403 - Forbidden error.

有没有什么方法可以使用我用来登录的 Google 帐户提取数据?因为一旦我在开发者控制台中创建了凭据,它们就会与 Google 帐户相关联,而不是与品牌帐户相关联.

Is there any way to extract data using the Google Account that I'm using to log in? Because once I create the credentials in developers console, they will be associated to the Google Account and not to the Brand Accounts.

我的 Google 帐户在品牌帐户上有经理角色.

My google account has Manager Role on the brand accounts.

我已搜索要在请求中使用的 onBehalfOfContentOwner 字段,但我不知道如何获取此 ID,我不确定这是否适用于我的情况,因为我们谈论的是品牌帐户,如果我错了,请纠正我.

I've search for the onBehalfOfContentOwner field to be used in requests, but I don't know how to get this ID, and I'm not sure if this is applicable in my situations, since we're talking about Brand Accounts, correct me if I'm wrong.

推荐答案

我在两天前就遇到了这个问题.事实证明这是可能的,只是没有记录,而且工作方式与您预期的有点不同:

I fought with this just two days ago. Turns out it IS possible, it's just undocumented and works a bit differently than you'd expect:

在开发者控制台中创建凭据后,它们将与 Google 帐户相关联,而不是与品牌帐户相关联.

Once I create the credentials in developers console, they will be associated to the Google Account and not to the Brand Accounts.

当我第一次尝试时,我也有同样的误解(甚至发现品牌帐户的 client_id).事实证明您不想使用品牌的 oauth 信息 - 您想使用自己的 client_id/client_secret 代表品牌帐户创建刷新令牌,然后使用它来创建身份验证令牌.

I had the same exact misconception when I first tried (even went so far as to find out the brand account's client_id). Turns out you don't want to use the brand's oauth info -- you want to use your own client_id/client_secret to create a refresh token on behalf of the brand account then use that to create auth tokens.

步骤:

  1. 使用您的主帐户通过 https://console.developers.google 创建 oauth client_id 和 client_secret.com/apis/credentials
  2. 编辑您刚刚添加的 client_id/client_secret 条目并添加https://developers.google.com/oauthplayground"到页面底部的授权重定向 URI".
  3. 我们将以懒惰的方式创建一个刷新令牌.转到 https://developers.google.com/oauthplayground/
  4. 点击右上角的齿轮并将访问类型设置为离线",然后点击使用您自己的 OAuth 凭据"并输入您在步骤 1 中创建的 client_id 和 client_secret.
  5. 选择您要授予其访问权限的范围.点击授权 API.
  6. 神奇之处在于:您现在会被要求选择一个帐户".在此处选择您要访问的品牌帐户,而不是您的主帐户.由于您有权访问它,即使您使用自己的 client_id 和 client_secret 也可以正常工作
  7. 在提示您时允许权限访问,然后您将被带回 oauth 游乐场.
  8. 点击兑换代币授权码"
  9. 获取刷新令牌并像往常一样使用它来根据需要生成身份验证令牌.
  1. Using your main account create an oauth client_id and client_secret via https://console.developers.google.com/apis/credentials
  2. Edit the client_id/client_secret entry you just added and add "https://developers.google.com/oauthplayground" to the "Authorized redirect URIs" at the bottom of the page.
  3. We're going to create a refresh token the lazy way. Go to https://developers.google.com/oauthplayground/
  4. Click the gears on the top right corner and set access type to "offline", then click "Use your own OAuth credentials" and enter the client_id and client_secret you created in step 1.
  5. Select the scopes you want to give it access to. Click authorize APIs.
  6. Here's the magic bit: You'll now be asked to "Choose an account". Choose the brand account you want to access here, NOT your main account. Since you have permission to access it this'll work fine even though you're using your own client_id and client_secret
  7. Allow the permission access when it prompts you, then you'll be brought back to the oauth playground.
  8. Click "Exchange authorization code for tokens"
  9. Grab the refresh token and use it like normal to generate auth tokens as needed.

恭喜,您现在可以通过 api 访问品牌帐号了!

Congratulations, you now have api access to the brand account!

希望对您有所帮助.

这篇关于YouTube API - 使用 Google 管理员帐户访问多个 youtube 频道(品牌帐户)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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