本文介绍了使用带有 onBehalfOfContentOwner 的 Youtube API 的 CMS 频道列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Youtube Data API 进行有针对性的查询(像这样示例) 用于 MCN 中的几个 CMS 帐户.我启用了正确的 API 并在 Google 的开发人员控制台上为已安装的应用程序设置了 oAuth.我确保调用正确的范围:

I am using the Youtube Data API to do targeted queries (like this example) for a few CMS accounts in an MCN. I enabled the proper APIs and set up an oAuth for an installed app on Google's developer console. I made sure to call the right scopes:

YOUTUBE_SCOPES = ["https://www.googleapis.com/auth/youtube.readonly",
                  "https://www.googleapis.com/auth/yt-analytics-monetary.readonly",
                  "https://www.googleapis.com/auth/youtubepartner"]

身份验证没有任何疑虑...

Authentication has no qualms...

(youtube, youtube_analytics) = get_authenticated_services(args)

直到进行健全性检查以列出与 CMS 关联的频道:

Until a sanity check to list the channels associated with the CMS:

youtube.channels().list(
    part='snippet,contentDetails', 
    managedByMe=True, 
    maxResults=50, 
    onBehalfOfContentOwner=CONTENT_OWNER_ID
  ).execute()

返回 403禁止访问"错误.我想知道这是不是因为我的 CMS 帐户没有管理员权限?

returning a 403 "Access Forbidden" Error. I am wondering if this is because I don't have admin privileges with my CMS account?

推荐答案

这里可能有两件事之一:

One of two things is probably at work here:

  1. 您正在使用授予 CMS 访问权限的帐户进行身份验证,但您在 youtube.channels().list() 方法中提供的 CONTENT_OWNER_ID 不正确.
  2. 您提供了正确的 CONTENT_OWNER_ID,但使用错误的帐户进行身份验证.
  1. You are authenticating with the account which grants access to the CMS, but the CONTENT_OWNER_ID you provided in your youtube.channels().list() method is incorrect.
  2. You are providing the correct CONTENT_OWNER_ID, but authenticating with the wrong account.

案例 1

您可能只需要在 youtube.channels().list() 方法中为 onBehalfOfContentOwner 参数包含正确的 CONTENT_OWNER_ID(不过,出于隐私考虑,您可能在帖子中将此留空).

Case 1

You may simply need to include the correct CONTENT_OWNER_ID for the onBehalfOfContentOwner parameter in your youtube.channels().list() method (although, you may have left this blank in your post for privacy).

要仔细检查,您可以通过此 .确保您通过了正确的身份验证(即,使用可以访问您想要的 CMS 的帐户),您将收到一个 JSON 响应,如下所示:

To double-check, you can find the value for CONTENT_OWNER_ID by invoking the API through this form. Make sure that you are authenticated correctly (ie., using the account with access to the CMS you want), and you'll receive a JSON response, something like this:

{
 "kind": "youtubePartner#contentOwnerList",
 "items": [
  {
   "kind": "youtubePartner#contentOwner",
   "id": CONTENT_OWNER_ID,
   "displayName": DISPLAY_NAME
   etc.
  }
 ]
}

只需在您的 channels().list() 方法中包含您希望从该响应中获得的任何 CONTENT_OWNER_ID(再次确保您已通过正确身份验证),并且瞧.

Simply include whatever CONTENT_OWNER_ID you want from this response in your channels().list() method (making sure, again, that you are properly authenticated), and voila.

如果这不能解决您的问题,那么您可能提供了正确的CONTENT_OWNER_ID,但是您使用了错误的帐户进行了身份验证.

If that doesn't solve your problem, then you may be providing the correct CONTENT_OWNER_ID, but you are authenticating with the wrong account.

在再次运行您的脚本之前,请仔细检查您是否删除了包含您的临时访问令牌的文件(它的文件名类似于YOUR_FILENAME-oauth2.json").然后,再次运行你的脚本;确保在提示选择身份验证帐户时,选择与您设置的 CONTENT_OWNER_ID 对应的一个.

Before running your script again, double-check that you deletethe file containing your temporary access token (it will have a filename like "YOUR_FILENAME-oauth2.json"). Then, run your script again; making sure that, when prompted to select an account for authentication, you select theone that corresponds with the CONTENT_OWNER_ID you set.

基本上,您进行身份验证的帐户与您提供的 CONTENT_OWNER_ID 之间必须达成一致.

Basically, there must be agreement between the account with which you authenticate, and the CONTENT_OWNER_ID you provide.

最后,您不需要 API 密钥来以这种方式调用 API;您需要一个 API 密钥一个经过适当身份验证的 OAuth 2.0 访问令牌.以下是文档.

Finally, you do not need an API key to invoke the API in this way; you either need an API key or a properly-authenticated OAuth 2.0 access token. Here are the docs.

这篇关于使用带有 onBehalfOfContentOwner 的 Youtube API 的 CMS 频道列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 22:47