Skip to content

gapi is not defined #112

@Faurby

Description

@Faurby

I am using Next.js. I have tried to read an earlier issue, and use the onLoad function, but just calling throws and error.
I have and API KEY and an OAUTH Client ID. Help pls :)

I have this basic code:

"use client";
import ApiCalendar from "react-google-calendar-api";

export default function Home() {
  const clientID = process.env.REACT_APP_CLIENT_ID;
  const apiKey = process.env.REACT_APP_CALENDAR_API_KEY;
  const calendarID = process.env.REACT_APP_CALENDAR_ID;

  const config = {
    clientId: clientID || "",
    apiKey: apiKey || "",
    scope: "https://www.googleapis.com/auth/calendar",
    discoveryDocs: [
      "https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest",
    ],
  };

  const apiCalendar = new ApiCalendar(config);

  apiCalendar.onLoad(() => {
    apiCalendar.handleAuthClick(); // Example on how to trigger auth manually
    apiCalendar
      .listUpcomingEvents(10, calendarID)
      .then((res: { result: { items: any } }) => {
        console.log(res.result.items);
      });
  });

  return apiCalendar
    .listUpcomingEvents(10, calendarID)
    .then((res: { result: { items: any } }) => {
      console.log(res.result.items);
    });
}

and I get the following error:

billede

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions