[Python] Google OAuth 400 invalid_request (Missing redirect_uri) with Python InstalledAppFlow...

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

  1. Stack

    Stack Membro Participativo

    I am trying to authenticate with the Google Blogger API from a Python script (in a standard Google Colab environment) and am consistently getting a 400: invalid_request error with the detail Missing required parameter: redirect_uri.

    This happens even with a minimal test script and brand new credentials created from scratch.

    Minimal Test Script:

    Python

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

    CLIENT_SECRET_FILE = 'credentials.json' SCOPES = ['https://www.googleapis.com/auth/blogger']

    print("--- Starting Minimal Authentication Test ---")

    try: flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES) auth_url, _ = flow.authorization_url(prompt='consent')

    print("\nPlease visit this URL to authorize:")
    print(auth_url)

    code = input('\nEnter the authorization code here: ')
    flow.fetch_token(code=code)
    creds = flow.credentials

    print("\nSUCCESS! Authentication credentials obtained.")


    except Exception as e: print(f"\n--- AN ERROR OCCURRED ---") print(e) Troubleshooting Steps Taken:

    Confirmed the OAuth 2.0 Client ID in Google Cloud is set to "Desktop app". Deleted and created new credentials multiple times. The issue occurs in both Replit and a fresh Google Colab environment. The google-auth-oauthlib library is version 1.2.2. I have manually inspected a freshly downloaded credentials.json file and it does contain the correct "urn:ietf:wg:eek:auth:2.0:eek:ob" redirect URI. Despite all of this, the flow.authorization_url() method generates a URL that, when visited, results in the Missing required parameter: redirect_uri error from Google's servers.

    Why would this happen when the credential type is correct and the client_secret.json file appears to be correctly formed?

    Continue reading...

Compartilhe esta Página