0

I am using google workspace to mange my calanders:

And I have this code to try and access it:

    $calendar_id = "***********@resource.calendar.google.com";
    $client = new \Google_Client();
    $client->setAuthConfig(storage_path('app/google-calendar/service-account-credentials.json'));
    $client->addScope(\Google_Service_Calendar::CALENDAR);

    // list all events
    $service = new \Google_Service_Calendar($client);
    $results = $service->events->listEvents($calendar_id);

    return $results;

But, I am getting this error:

"{\n \"error\": {\n  \"errors\": [\n   {\n    \"domain\": \"global\",\n    \"reason\": \"notFound\",\n    \"message\": \"Not Found\"\n   }\n  ],\n  \"code\": 404,\n  \"message\": \"Not Found\"\n }\n}\n"

Any ideas?

rook99
  • 1,034
  • 10
  • 34

1 Answers1

0

What's missing here is the calendar that is supposed to be accessed, you can add the line below to achieve this (The line was taken from this answer, there is also a lot more code there but the line below is the only thing missing from your code)

$client->setSubject(
            subject: "Here, you have to enter your Google Workspace Account Username"
        );

The reason why you get the "Not found" error message is because the service account itself was trying to show it's own calendar however service accounts do not have a calendar to show and that's why you don't get any other type of error message.

Hope this helps!

Rene Olivo
  • 526
  • 1
  • 10