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

查看:349
本文介绍了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-禁止的错误.

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代表品牌帐户创建刷新令牌,然后使用该令牌创建auth令牌.

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. ,也可以正常工作.
  8. 在提示您时允许权限访问,然后您将被带回oauth游乐场.
  9. 点击令牌的交换授权码"
  10. 获取刷新令牌并像往常一样使用它来根据需要生成身份验证令牌.
  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天全站免登陆