4

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) 

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() 

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

5
  • 1
    In order to call CMS account's channel list (or anything related to CMS), you should have the proper API keys. If you would like to use "Try It", you have to login with CMS account and choose the channel which is assigned for CMS. Commented Jan 28, 2016 at 2:12
  • @iwocan so in addition to setting up oAuth, I need to request an API key? From the documentation it seemed either works. I'll give it a try! Commented Jan 28, 2016 at 3:30
  • Should adding the key=API_KEY argument in .list() solve my problem? I am still getting a 403 Commented Jan 29, 2016 at 20:33
  • You don't need an API key if you are already providing an access token with your request. See my answer. Commented Feb 24, 2016 at 18:51
  • @leonyin Can you list out your script code? and im going to fetch the reporting , but never success Commented Feb 24, 2020 at 6:40

1 Answer 1

6

One of two things is probably at work here:

  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.

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

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

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.

Case 2

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.

Before running your script again, double-check that you delete the 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 the one that corresponds with the CONTENT_OWNER_ID you set.

tl:dr;

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

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Daniel, just revisiting this now and it works.
Could you please help, how can I extract CONTENT_OWNER_ID, following the comment I don't understand what should I do.
I don't understand how to get correct CONNTEN_OWNER_ID either
could anyone tell me how to get CONNTEN_OWNER_ID
How to get CONTENT_OWNER_ID?
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.