1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why does auth.authenticate_user() in Google Colab not give access to my personal...

Discussão em 'Python' iniciado por Stack, Setembro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to access my Google Calendar events from Google Colab using the Google Calendar API.

    from google.colab import auth
    from googleapiclient.discovery import build
    import google.auth
    import datetime

    auth.authenticate_user()

    PROJECT = 'workspace-api'
    SCOPES = ['https://www.googleapis.com/auth/calendar.readonly']
    creds, _ = google.auth.default(scopes=SCOPES)
    print("Account: ",creds.service_account_email)

    service = build("calendar", "v3", credentials=creds)

    now = datetime.datetime.now(tz=datetime.timezone.utc).isoformat() + "Z"
    events_result = (
    service.events()
    .list(
    calendarId="primary",
    timeMin=now,
    maxResults=10,
    singleEvents=True,
    orderBy="startTime",
    )
    .execute()
    )


    and here is the output and email: Account: default WARNING:googleapiclient.http:Encountered 403 Forbidden with reason "insufficientPermissions"

    I tried using auth.authenticate_user() in Google Colab to connect to the Google Calendar API without manually uploading credentials or using an OAuth consent flow. My assumption was that this would authenticate me using my personal Google account.

    However:

    1. When I call google.auth.default(scopes=SCOPES), the returned credentials show "default" instead of my Gmail address.
    2. When I fetch events from the "primary" calendar, I either get no results or an insufficient permissions error.

    I expected Colab authentication to give me access to my personal Google Calendar, but it seems to return application default credentials that aren’t linked to my account.

    I can't use oauth because colab doesn't have a browser for flow.run_local_server

    Continue reading...

Compartilhe esta Página