问题
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?
回答1:
One of two things is probably at work here:
- You are authenticating with the account which grants access to the CMS, but the
CONTENT_OWNER_ID
you provided in youryoutube.channels().list()
method is incorrect. - 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.
来源:https://stackoverflow.com/questions/35050537/cms-channel-list-using-youtube-api-with-onbehalfofcontentowner