Issue
I currently have a private Google (that includes YouTube) account with a YouTube channel. I want to create and generally manage playlists on channel account (instead of private account/channel). When I'm querying POST https://www.googleapis.com/youtube/v3/playlists
I can only manage my private account.
I have tried this:
# Generated by Google Bard AI
curl -X GET \
-H "Authorization: Bearer [YOUR_API_KEY]" \
https://www.googleapis.com/youtube/v3/channels
I can see only my private account main channel.
And this:
# From: https://developers.google.com/youtube/v3/docs/channels/list
curl --request POST \
'https://youtube.googleapis.com/youtube/v3/playlists?part=snippet,status&onBehalfOfContentOwnerChannel=[ChannelID]&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"snippet":{"title":"Test 1","description":"Test playlist."},"status":{"privacyStatus":"unlisted"}' \
--compressed
Returns:
{
"error": {
"code": 500,
"message": "Internal error encountered.",
"errors": [
{
"message": "Missing content owner id.",
"domain": "youtube.api.v3.RequestContextError",
"reason": "ERROR_CONTENT_OWNER_CHANNEL_WITHOUT_CONTENT_OWNER"
}
],
"status": "INTERNAL"
}
}
When I apply my private account channel ID, it returns:
{
"error": {
"code": 403,
"message": "The authenticated user cannot act on behalf of the specified Google account.",
"errors": [
{
"message": "The authenticated user cannot act on behalf of the specified Google account.",
"domain": "youtube.common",
"reason": "accountDelegationForbidden"
}
]
}
}
As far as I understand, as long I'm not a YouTube Partner (which I'm not) I can't use it... Right?
Solution
This worked:
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file(
'client_secret.json',
['https://www.googleapis.com/auth/youtube']
)
credentials = flow.run_local_server()
youtube = build(
'youtube',
'v3',
credentials=credentials
)
body = dict(
snippet=dict(
title='Test playlist',
description='Playlist generated with YouTube API.'
),
status=dict(
privacyStatus='private'
)
)
playlists_insert_response = youtube.playlists().insert(
part='snippet, status',
body=body
).execute()
playlist_id = playlists_insert_response.get('id')
print(f'New playlist ID: {playlist_id}.')
During verification process I've selected my channel to verify in app. Playlist has been created on that channel.
Answered By - Anonymous Answer Checked By - Marilyn (WPSolving Volunteer)