Slimesus
Slimesus

Reputation: 41

Google api/Youtube data api how to swap channels after app authorization

Hi so i found this thing... so i was using a python script to upload a youtube video.

from Google import Create_Service
from googleapiclient.http import MediaFileUpload

CLIENT_SECRET_FILE = 'client_secret.json'
API_NAME = 'youtube'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/youtube.upload']

service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

request_body = {
    'snippet': {
        'categoryI': 19,
        'title': '<title>',
        'description': '<description>',
        'tags': [<tags>]
    },
    'status': {
        'privacyStatus': 'public',
        'selfDeclaredMadeForKids': False, 
    },
    'notifySubscribers': True
}

mediaFile = MediaFileUpload('video_f.mp4')


response_upload = service.videos().insert(
    part='snippet,status',
    body=request_body,
    media_body=mediaFile
).execute()

and everything worked, but now as i need to change the youtube channel that it uploads to it doesn't...

I tried deleting the client_secrets.json and replacing it for a new one from other google account with new oauth but it didn't work, python was still uploading to the old channel. Also this worked somehow:

from Google import Create_Service
from googleapiclient.http import MediaFileUpload

CLIENT_SECRET_FILE = '' # <------- no client_secrets.json
API_NAME = 'youtube'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/youtube.upload']

service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)

request_body = {
    'snippet': {
        'categoryI': 19,
        'title': '<title>',
        'description': '<description>',
        'tags': [<tags>]
    },
    'status': {
        'privacyStatus': 'public',
        'selfDeclaredMadeForKids': False, 
    },
    'notifySubscribers': True
}

mediaFile = MediaFileUpload('video_f.mp4')


response_upload = service.videos().insert(
    part='snippet,status',
    body=request_body,
    media_body=mediaFile
).execute()

it even works without the client file. I also tried deleting pycache folder, did nothing. searched the web, nothing. So now im here asking for help.

Upvotes: 0

Views: 226

Answers (2)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117281

YouTube authorization is channel based, when you authorized it the first time it ran you picked a channel you can only access this channel.

The access token and refresh token stored in your token pickle file grant you access to that channel only.

You will need to authorize it again this time picking a different channel if you want to upload to that one. renaming the token pickle file will cause it too request authorization again

you can have more than one token pickle to store authorization for the different channels

Upvotes: 1

Slimesus
Slimesus

Reputation: 41

i just needed to delete the .pickle file

Upvotes: 0

Related Questions