[Python] Google API Python | ValueError: Authorized user info was not in the expected format,...

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    Traceback (most recent call last):
    creds = Credentials.from_authorized_user_file('credent.json', SCOPES)
    File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python310\lib\site-packages\google\oauth2\credentials.py", line 440, in from_authorized_user_file
    return cls.from_authorized_user_info(data, scopes)
    File "C:\Users\WINDOWS\AppData\Local\Programs\Python\Python310\lib\site-packages\google\oauth2\credentials.py", line 390, in from_authorized_user_info
    raise ValueError(
    ValueError: Authorized user info was not in the expected format, missing fields client_secret, client_id, refresh_token.


    I created an OAuth Client ID, set the application type there to Desktop App, downloaded the json file, then tried to login (code below) and got an error, I entered the file, it is in this order (example below), later I removed 'installed' from json , the error is different now ValueError: Authorized user info was not in the expected format, missing fields refresh_token.

    JSON EXAMPLE

    {"installed":
    {"client_id": "client_id_my",
    "project_id": "projectname123",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://oauth2.googleapis.com/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "SECRET",
    "redirect_uris": ["http://localhost"]}
    }


    import os.path

    from google.oauth2.credentials import Credentials
    SCOPES = ['https://www.googleapis.com/auth/classroom.courses.readonly']


    creds = Credentials.from_authorized_user_file('credent.json', SCOPES)

    Continue reading...

Compartilhe esta Página