Last active
August 29, 2015 14:20
-
-
Save nicekiwi/c13136cdd55fedc1fa5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'vendor/autoload.php'; | |
$opts = [ | |
'calendar-id' => 're2h5k3qcl80edoihv27bn6i3c@group.calendar.google.com', | |
'client-email' => 'xxxxxxxxxxxxxxxxxxxxx', | |
'private-key' => file_get_contents('auth-key.p12'), | |
'scopes' => [ | |
'https://www.googleapis.com/auth/calendar' | |
], | |
]; | |
$credentials = new Google_Auth_AssertionCredentials( | |
$opts['client-email'], | |
$opts['scopes'], | |
$opts['private-key'] | |
); | |
$client = new Google_Client(); | |
$client->setAssertionCredentials($credentials); | |
if ($client->getAuth()->isAccessTokenExpired()) { | |
$client->getAuth()->refreshTokenWithAssertion(); | |
} | |
$service = new Google_Service_Calendar($client); | |
$event = new Google_Service_Calendar_Event(); | |
$event->setSummary('Appointment'); | |
$event->setLocation('Somewhere'); | |
$start = new Google_Service_Calendar_EventDateTime(); | |
$start->setDateTime('2015-05-20T10:00:00.000-07:00'); | |
$event->setStart($start); | |
$end = new Google_Service_Calendar_EventDateTime(); | |
$end->setDateTime('2015-05-25T10:25:00.000-07:00'); | |
$event->setEnd($end); | |
$attendee1 = new Google_Service_Calendar_EventAttendee(); | |
$attendee1->setEmail('email@domain.com'); | |
$attendees = array($attendee1); | |
$event->attendees = $attendees; | |
$createdEvent = $service->events->insert($opts['calendar-id'], $event); | |
echo $createdEvent->getId(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment