I am getting events from calendar using Google Calendar PHP API.
Everything works with the initial calendar, but now I am trying to use the same setup to receive events from another calendar (same Google account).
There's a following error in the log:
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://www.googleapis.com/calendar/v3/calendars/CALENDAR_ID.calendar.google.com/events?maxResults=999&orderBy=startTime&singleEvents=true&timeZone=Europe%2FTallinn&timeMin=2016-09-19T00%3A01%3A00Z&timeMax=2018-07-17T00%3A00%3A00Z: (404) Not Found' in /www/apache/domains/www.domain.ee/htdocs/wp-content/themes/THEME/booking/vendor/google/apiclient/src/Google/Http/REST.php:79
And here's the code: (only thing I chaged is $calendarId
)
require_once 'vendor/autoload.php';
$client_email = '[email protected]';
$private_key = file_get_contents('name.p12');
$scopes = array('https://www.googleapis.com/auth/calendar');
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Calendar($client);
// Print the next 999 events on the user's calendar.
$calendarId = '[email protected]';
$optParams = array(
'maxResults' => 999,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeZone' => 'Europe/Tallinn',
'timeMin' => '2016-09-19T00:01:00Z',
'timeMax' => '2018-07-17T00:00:00Z',
);
$results = $service->events->listEvents($calendarId, $optParams);
Inserting same data into Google APIs Explorer returns exactly the events I am looking for.