PHP code example of ft-ugm / google-calendar

1. Go to this page and download the library: Download ft-ugm/google-calendar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ft-ugm / google-calendar example snippets


use FtUgm\GoogleCalendar\GoogleCalendar;

$calendar = new GoogleCalendar([
	'base_url' => 'https://calendar-api.ft.ugm.ac.id',
	'token' => 'GOOGLE_CALENDAR_API_TOKEN',
]);

use FtUgm\GoogleCalendar\Event;

$event = new Event([
	'summary' => 'IT Team Discussion',
	'description' => 'Discussion about the development of the correspondence service.',
	'start' => [
		'dateTime' => '2026-09-15T10:00:00+07:00',
		'timeZone' => 'Asia/Jakarta',
	],
	'end' => [
		'dateTime' => '2026-09-15T11:00:00+07:00',
		'timeZone' => 'Asia/Jakarta',
	],
	'location' => 'IT Room',
	'attendees' => [
		[
			'email' => '[email protected]',
		],
	],
]);

$event = $calendar->createEvent($event);

echo $event->getId();
echo $event->getHtmlLink();

'start' => new \DateTime(
	'2026-09-15 10:00:00',
	new \DateTimeZone('Asia/Jakarta')
),
'end' => new \DateTime(
	'2026-09-15 11:00:00',
	new \DateTimeZone('Asia/Jakarta')
),

'start' => [
	'dateTime' => '2026-09-15T10:00:00+07:00',
],
'end' => [
	'dateTime' => '2026-09-15T11:00:00+07:00',
],

'start' => [
	'date' => '2026-09-15',
],
'end' => [
	'date' => '2026-09-16',
],

$event = $calendar->getEvent($eventId);

echo $event->getSummary();
echo $event->getHtmlLink();

$event = new Event([
	'summary' => 'IT Team Discussion - Revised',
	'description' => 'Discussion about the development of the e-office service.',
	'start' => [
		'dateTime' => '2026-09-16T13:00:00+07:00',
		'timeZone' => 'Asia/Jakarta',
	],
	'end' => [
		'dateTime' => '2026-09-16T14:00:00+07:00',
		'timeZone' => 'Asia/Jakarta',
	],
	'attendees' => [
		[
			'email' => '[email protected]',
		],
		[
			'email' => '[email protected]',
		],
		[
			'email' => '[email protected]',
		],
	],
]);

$event = $calendar->updateEvent($eventId, $event);

$event = new Event([
	'summary' => 'Final Title (For Real This Time)',
]);

$event = $calendar->patchEvent($eventId, $event);

$calendar->deleteEvent($eventId);

use FtUgm\GoogleCalendar\GoogleCalendarException;

try {
	$event = $calendar->getEvent($eventId);
} catch (GoogleCalendarException $e) {
	echo $e->getMessage();
	echo $e->getCode();
}

$response = $e->getResponse();