I'm working on a cron script to check my Google calendar on a daily basis. I'd like to know if it's possible to use Application-Specific Passwords (see: https://support.google.com/accounts/answer/185833?hl=it) and insert the generated password in my script. The OAUTH requires the user interaction and since I'm working on a script I cannot follow that way. I've also read about the "service accounts", but hope I could avoid it just by using Application-Specific Passwords. What's the difference? Any hint?
Many thanks Francesco
EDIT1: The code I'm trying with:
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
//The json file you got after creating the service account
putenv('GOOGLE_APPLICATION_CREDENTIALS=test-calendario-268115-5452ff6f57e8.json');
$client->useApplicationDefaultCredentials();
$client->setApplicationName("test_calendar");
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();
EDIT2: $service->calendarList->listCalendarList() gives empty list use:
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
//The json file you got after creating the service account
putenv('GOOGLE_APPLICATION_CREDENTIALS=test-calendario-268115-5452ff6f57e8.json');
$client->useApplicationDefaultCredentials();
$client->setApplicationName("test_calendar");
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);
$listEvents = $service->events->listEvents("...@group.calendar.google.com");// taken from sharing calendar settings
$events = $listEvents->getItems();
print_r($events);