Updating the (Upload a Video) to Youtube using Python code

38 Views Asked by At

The official youtube documentation for uploading a video using python is broken if you're trying to authenticate non-locally. The deprecated oauth2client uses an out-of-bound "flow" / authentication method that google no longer accepts.

The "Error 400: invalid_request" shows up if you try to run this code, and authenticate non-locally using the given test code.

ethan@myTerminal % python upload.py --file="/home/work/shared/ethan/yt-auto-upload/recordings/test/test_video.mp4" --title="An Awesome Video" --description="Welcome" --keywords="Games" --category="28" --privacyStatus="public" --noauth_local_webserver

Go to the following link in your browser:

https://accounts.google.com/o/oauth2/auth?scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyoutube.upload&redirect_uri=myURN&response_type=code&client_id=myID

Enter verification code:

The fix given by the oauth2client is to switch to using oauthlib, but I'm unsure of how to recreate the "authentication flow", especially if I want to do it using a link (so I can authenticate non-locally).

I've taken a peek at the documentation for the 'deviceClient' type of API, and it seems that you can create a working redirect URI using the "prepare_request_uri" function at the bottom of the page I linked.

I would appreciate any help in fusing all this knowledge together to create a working, updated version of youtube's automatic video uploader.

The attached github has the original code, updated to work with Python 3, "upload.py" created by youtube. It also holds my work in progress version "ethanupload.py" that doesn't authenticate properly.

1

There are 1 best solutions below

2
Ayşe Nur Aslan On

If you get an error that says “400 invalid_request” or “Access blocked: App sent an invalid request,” it means the app uses an authorization method that Google doesn't allow. Google has safe ways for you to sign in and share your Google Account data with third-party apps and sites.