[Python] Invalid request from Google API in python

Discussão em 'Python' iniciado por Stack, Junho 9, 2025.

  1. Stack

    Stack Membro Participativo

    I trying to write code to access the Youtube API in python. I followed the sample code get authenticated for Google API. When I run this I get a message


    Access blocked: MyAPP request is invalid
    ​

    I have no idea why I get this. Any advise would be appreciated.

    from googleapiclient.discovery import build
    from google_auth_oauthlib.flow import InstalledAppFlow

    # Replace with the path to your downloaded client_secret.json file
    CLIENT_SECRETS_FILE = 'client_secret.json'

    # Define the scopes your application needs
    SCOPES = ['https://www.googleapis.com/auth/youtube.readonly']

    API_SERVICE_NAME = 'youtube'
    API_VERSION = 'v3'

    def get_authenticated_service():
    flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
    credentials = flow.run_local_server(open_browser=False) # Or flow.run_local_server() for web apps
    return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)

    # Now you can use the authenticated service to make YouTube API calls
    youtube = get_authenticated_service()

    Continue reading...

Compartilhe esta Página