Using the YouTube Analytics API with a CMS account

我是研究僧i 提交于 2020-01-10 10:56:25

问题


I'm getting a 403 Forbidden error when trying to get youtube analytics api data using a CMS account.

Just to confirm, is a CMS account the same thing as a Service account?

I can get analytics data for channels that are owned by the oauth2 user but I get the 403 on any other channels that I have access to through my CMS account but am not the content owner of. (I have Administrator account level on the CMS account and the channels I get 403 error on have "Managed" relationship)

Question: Are there any plans to have youtube.analytics api support for querying channels managed under a CMS account?

It seems that since I can use that account to get all the analytics data for these channels using the CMS UI that I should be able to do the same using the API.


回答1:


A YouTube Content Management System account is not the same thing as a Service Account. You won't get far with the YouTube APIs if you authenticate as a Service Account, since that Service Account won't have access to any actual YouTube channels. Authenticating as a CMS account, however, will give you what you want.

A lot of this recently made it into production, so let me lay out the full steps here explaining how folks with YouTube CMS access can run YouTube Analytics API reports against the channels and videos they manage.

(Optional) While authorized via OAuth 2 as the CMS account, using both the https://www.googleapis.com/auth/youtube.readonly and https://www.googleapis.com/auth/youtubepartner scopes, make a YouTube Data API v3 channels.list() call with the following parameters: part=snippet,contentDetails, managedByMe=true, maxResults=50, onBehalfOfContentOwner=CONTENT_OWNER_ID. CONTENT_OWNER_ID is the one value that you'll have to hardcode here, and it should be set to the "partner code" for your YouTube CMS account. This will give you back a list of up to 50 channels that your CMS account manages. (If you need more than 50, you'll need to page through the results.) The id of each channel will be returned in channel.id, and other useful information (like the uploads list id, if you want to get the list of videos in that channel) will also be returned.

If you already know the UC... channel id for the channel you want to run reports against, you could skip that step and go directly to the Analytics report.

To run a channel-level report on a managed channel, while authorized as the CMS account, make a YouTube Analytics API request with the following parameters: ids=contentOwner==CONTENT_OWNER_ID, filters=channel==UC..., and then any other report parameters you want.

To run a video-level report, set ids=contentOwner==CONTENT_OWNER_ID and filters=video==VIDEO_ID, where VIDEO_ID is the id of any video in any channel that the CMS account manages.

There are more details about content owner reports in the docs.



来源:https://stackoverflow.com/questions/15554106/using-the-youtube-analytics-api-with-a-cms-account

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!