Hey,
I feel like I'm getting close with getting this to work...I think I've gotten it to authenticate now (at least it's not throwing an exception for that). Right now, I'm getting this error message:
Fatal error: Uncaught exception 'Google_ServiceException' with message
'Error calling GET
https://www.googleapis.com/calendar/v3/calendars/myCal...@example.com/events:
(404) Not Found'
Here's my code...possibly a problem with line $client->setAssertionCredentials, specifically, the 2nd argument.
ini_set('display_errors', 1);
session_start();
require_once "google-api-php-client/src/Google_Client.php";
require_once "google-api-php-client/src/contrib/Google_CalendarService.php";
const CLIENT_ID = 'your-client-id-here';
const SERVICE_ACCOUNT_NAME = 'your-service-account-name-here';
const KEY_FILE = 'your-privatekey-file-here.p12';
$client = new Google_Client();
$client->setApplicationName("My Calendar App");
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('
https://www.googleapis.com/auth/calendar'),
$key)
);
$client->setClientId(CLIENT_ID);
$service = new Google_CalendarService($client);
foreach ($service->events->listEvents('
myCal...@example.com')->items As $item) {
echo $item->start->date . " : " . $item->end->date . " : " . $item->id . '<br>';
}
print_r($service->events->listEvents('
myCal...@example.com')->items);
Any ideas? Thanks!