Youtube reporting API HttpError 403 error - youtube

On my google account (not a Primary account), I have created OAuth credentials which have access to CMS and it's Channels. Using this credentials I am able to fetch data from YouTube Analytics API, so here no problem.
However, when I am trying access YouTube Reporting API, I am only getting the list of reports of Content Owners Reports with an addition of onBehalfOfContentOwner=cms._id parameter and the CMS ID.
def list_report_types(cms):
reporting = youtube.reporting()
request = reporting.reportTypes().list(onBehalfOfContentOwner=cms._id)
results = youtube.query(request)
return results.get('reportTypes')
report_types = list_report_types(cms)
Can anyone help me to also get the list of reports of Channels also?
So when I try to schedule a channel_basic_a2 report, it gives me below error
HttpError 403 when requesting https://youtubereporting.googleapis.com/v1/jobs?alt=json&onBehalfOfContentOwner=cmsid returned "The caller does not have permission">
Thanks in advance.

Two possible issues:
Are the oauth credentials you are using service account credentials? Service accounts do not work for the Youtube Reporting API. See this answer.
Also, have you checked your scopes definition?

Related

Youtube brand account cannot use an internal youtube API-client

I've created an internal app in the google cloud console for uploading videos with an application.
When choosing the youtube channel (brand account) for authentication, I get a 403: org_internal. If I choose my "personal" account, I get a working token.
I also tried the OnBehalfOfContentOwner and OnBehalfOfContentOwnerChannel parameters which resulted in either the same behaviour or a googleapi: Error 403: Access forbidden. The request may not be properly authorized., forbidden response
I have verified that:
I am using G-Suite
the cloud app is bound to the organisation
the channel was created by an organisation-account
the "primary owner" of the youtube channel is in the organisation
I would like to know how to use a youtube brand account in combination with an internal cloud api client accessing the youtube.upload scope or if making it external (which I do not want) is the only option.
Edit/Note: There is only one account in the organisation which is me.

How to get Youtube video views by date range

I am trying to get youtube video views by date range and it is working fine with oAuth. But I am using cron script to collect those data through service account, when I try to execute the script it says:
Error calling GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUC88Bq63MDJi9szYPEGfv7YA&start-date=2014-02-01&end-date=2016-06-29&metrics=views:
(400) Invalid query. Query did not conform to the expectations".
Could you please help me anyone to resolve this issue. Thanks in advance.
Using service account is not supported by Youtube Analytics and Reporting API
The service account flow supports server-to-server interactions that do not access user information. However, the YouTube Reporting API and YouTube Analytics API do not support this flow. Since there is no way to link a Service Account to a YouTube account, attempts to authorize requests with this flow will generate an error.
Unfortunately, you need to do OAuth2 to get your report.
Resources you can check for information:
Youtube Analytics API PHP Invalid query. Query did not conform to the expectations
Implement OAuth 2.0 Authorization

Youtube Content ID API has not been used - error 403

I'm trying to get my content-owner-id for upload videos to other channels that I have, as described here.
I'm using the code below to get content-owner-id: (PHP)
$youtubePartner = new Google_Service_YouTubePartner($this->client);
$contentOwnersListResponse = $youtubePartner->contentOwners->listContentOwners(
array('fetchMine' => true));
$contentOwnerId = $contentOwnersListResponse['items'][0]['id'];
And this is the error I got:
A service error occurred: Error calling GET
googleapis.com/youtube/partner/v1/contentOwners?fetchMine=true:
(403) Access Not Configured. Youtube Content ID API has not been used
in project XXXXXXXXXXXXX before or it is disabled. Enable it by
visiting
console.developers.google.com/apis/api/youtubePartner/overview?project=XXXXXXXXXX
then retry. If you enabled this API recently, wait a few minutes for
the action to propagate to our systems and retry.
I tried to go the the link https://console.developers.google.com/apis/api/youtubePartner/overview?project=XXXXXXXXXX but I get "The API doesn't exist or you don't have permission to access it".
Then I searched on google and find out that I need to become a CMS youtube account (I'm also a youtube partner). I also tried to go to cms.youtube.com and log in with my youtube account but I got:
Your Google Account is not linked with YouTube Content Manager. Please
try a different account or contact your Technical Account Manager for
assistance.
Can anyone explain me how to connect to CMS account?
Based from this thread:
You don't see it in the list auf available APIs, unless your account is connected to a CMS and some time has past... It takes 7-14 days unless the Content ID API is available for your account. This is a information i got from the support, but they told me, that it is an automated step.
Your account needs to be connected with a content owner. Be noted that a content owner and a partnered channel are not the same thing.
From this documentation, to request data from a YouTube Content Owner, you need to set the ids parameter value to contentOwner==OWNER_NAME, where OWNER_NAME is the content owner ID.
Check these related SO questions:
How do I get revenue reports from a YouTube CMS account using an API (for an MCN)?
Using the YouTube Analytics API with a CMS account

How do I get metrics for youtube users?

I am new to youtube APIs, I am trying the API explorer here : https://developers.google.com/youtube/analytics/v1/
I am trying to get details about a particular youtube user. I am entering the following things to execute the method in the API explorer :
channel id, start date, end date and metrics. When I execute i get the following 403 Forbidden error with you do not have permission to execute this method as a message.
All the details I am entering are correct.
Does youtube doesnt allow to fetch details of other users ? If it allows, what am I doing wrong here? Thanks !
Unless you are a CMS that manages the channel you are requesting data for, Youtube will not allow you to access their analytics data. The analytics API only allows you to request data for the channels owned by the current authenticated user.

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.
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.

Resources