Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the YouTube Analytics API with a CMS account

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.

like image 518
kk64738 Avatar asked Mar 21 '13 17:03

kk64738


People also ask

Is there an API for YouTube Analytics?

The YouTube Analytics API allows both channel owners and Content Managers to download custom reports of their YouTube Analytics data. The YouTube Reporting API allows you to download entire data sets in bulk.

Is the YouTube API free?

YouTube Data API costs are based on quota usage, and all requests will incur at least a 1-point quota cost. For each project, you're allowed 10,000 free quota units per day. You can use the quota calculator to determine your quota costs. If you need more queries, you can apply for higher quotas, but pricing may vary.

Can you export YouTube Analytics?

You can export data while looking at either a channel or a specific video. If you're a content manager, you can also download reports for multiple channels. Downloaded reports are limited to 500 rows. Use the YouTube Analytics API to download more than 500 rows of data.


1 Answers

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.

like image 76
Jeff Posnick Avatar answered Oct 03 '22 07:10

Jeff Posnick