Python YouTube API Tutorial: Using OAuth to Access User Accounts

Corey Schafer · 153K views · 2020 · 43:21

Open on YouTube

Python, Ruby & scripting languagesWeb developmenttutorial

Why Stack Overflow recommends it

Stack Overflow users cite it as the source of the OAuth token-storage and refresh code they are building on when they hit credential or authorization errors.

Recommended by 0 people across 0 different months, 2021 to 2022.

What it is

Corey Schafer's Python tutorial on using OAuth2 with the YouTube Data API so a script can act on a user's account. He walks through the auth flow and shows how he uses it to reach his own private and unlisted videos, with a downloadable code gist.

What people said

Cites programmer_noob · 2021-02 · Stack Overflow · on “YouTube Data API v3 Refresh Token Keeps Expiring on App with Publishing Status Set to Testing”

WHAT I'M TRYING TO DO: I'm trying to build a Python 3.9 program to make daily calls of the YouTube Data API v3 using OAuth2 credentials (set to the "testing" publishing status, as a "web application" type, and "external" user type), by storing the refresh token to get a new access token each time I make a unique call. I've been using the [LINK] , the Python code examples from the Google API repository on GitHub [LINK] , along with this OAuth token solution I found from Corey Schafer on YouTube [this video] . WHAT I'VE TRIED SO FAR: Here's my Python code (I've scrambled the playlist ID for the sake of anonymity, but the code runs fine if you put in your own playlist ID for a channel that you have

Cites Kostia · 2022-10 · Stack Overflow · on “Error in Python script, when trying to save Credentials after login with OAuth2 to Youtube Account”

I have some error in this code, but cannt figure out where. import os import pickle from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request from googleapiclient.discovery import build credentials = None # token.pickle stores the user's credentials from previously successful logins if os.path.exists('token.pickle'): print('Loading Credentials From File...') with open('token.pickle', 'rb') as token: credentials = pickle.load(token) # If there are no valid credentials available, then either refresh the token or log in. if not credentials or not credentials.valid: if credentials and credentials.expired and credentials.refresh_token: print('Refres

Cites PixelGMS · 2022-11 · Stack Overflow · on “I get an Error 400 on Google when using the authorization link for my Python Google API programs, including ones I know worked for others”

I'm working on a code that requires the use of google_auth_oauthlib, but the authorization link that my code produces sends me to a "400. That’s an error. The server cannot process the request because it is malformed. It should not be retried. That’s all we know." page. So I switched tracks and moved to a tutorial [this video] and copied the code: import os from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build import pickle credentials = None # token.pickle stores the user's credentials from previously successful logins if os.path.exists('token.pickle'): print('Loading Credentials From File...') with open('token.pickle', 'rb') as token: credentials = p