Using own backend, to create calendar events

After spending several days and super many hours, googling, trying out different stuff, and reading - I am stuck. The integration just doesn't work and doesnt make any sense for me why.

I just want our backend (in PHP) to create calendar events into a single user's calendar (Google Calendar).

It has worked before like 4 years ago, it doesn't work now. I read upon the PHP Google Client and the IAM and the Service account (as it has worked with that before) and still can't make it work.

The response I get is:
{ "error": "unauthorized_client", "error_description": "Unauthorized client or scope in request." }

This is what I've wrote in PHP:

 

 

 

$data = array(
      'end' => (object) array(
        'dateTime' => '2023-10-15T17:00:00',
        'timeZone'=> 'Europe/Copenhagen'
      ),
      'start' => (object) array(
        'dateTime' => '2023-10-15T15:00:00',
        'timeZone'=> 'Europe/Copenhagen'
      ),
      'summary' => 'Something here!',
    );
   
    $client = new Google_Client();
    $client->setAuthConfig('/private_key.json');
    $client->setScopes("https://www.googleapis.com/auth/calendar");
    $client->setSubject('something');
    $client->setApplicationName("the application name");
    $calendarId = 'the@calendarid.com';

      $event   = new Google\Service\Calendar\Event( $data );
      $service = new Google\Service\Calendar($client);
      $service->events->insert($calendarId, $event);

 

 

 


Apparently, I'm just too dumb to make this Google Client authorise to make these events.

If anyone can help, please do. As I wrote, it has worked for many years, and then suddenly stopped working. I tried to update the PHP client, tried checking the IAM and read about the roles and gave  the roles that were needed, but somehow it still doesn't work.

 

0 0 400
0 REPLIES 0