Get Video Details From The YouTube API Using Python

November - 2021

This is the example from:

NOTE: I'm not sure if it's completely since it doesn't show how to use the token. I've got another page on the site that shows how to do that.

TODO: Update this to make sure it's a complete, stand alone sample

TODO: Link to other pages if necessary

TODO: Figure out more about what OAUTHLIB_INSECURE_TRANSPORT is doing in here since I didn't need it for my other scripts.

#!/usr/bin/env python3 

import os

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = [""]

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube =
        api_service_name, api_version, credentials=credentials)

    request = youtube.videos().list(
    response = request.execute()


if __name__ == "__main__":