Connect google calendar api with account

Hey guys, i want to connect google calendar api, and fetch events to get all meetings i have during some period of time.

Main problem i have right now is which access_token do i need to provide in gapi client? This is my current implementation on initialisation of gapi client where i pass session:

const initClient = useCallback(async () => {
    if (window.gapiIsInitialized) return

    console.log('init gapi')
    return gapi.client.init(GAPI_CONFIG).then(
      () => {
        // const access_token =
        //   session.user.identities.find((acct) => acct.provider === 'google')
        //     ?.access_token ?? ''

        if (session?.access_token === '') return

        gapi.client.setToken({ access_token: session.access_token })

        window.gapiIsInitialized = true
        return
      },
      (e) => {
        window.gapiIsLoading = false
        console.info('error init gapi client', e.details)
      }
    )
  }, [])


The problem i am getting right now is this one:

message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
Was this page helpful?