-
-
Save fontenele/8482d143c61a69e5f17f5ae5c7e2728c to your computer and use it in GitHub Desktop.
Use Google Calendar API
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 | |
include_once 'google-api-php-client/vendor/autoload.php'; | |
$client = new Google_Client(); | |
$application_creds = 'service-account-credentials.json'; | |
$credentials_file = file_exists($application_creds) ? $application_creds : false; | |
define("SCOPE",Google_Service_Calendar::CALENDAR); | |
define("APP_NAME","Google Calendar API PHP"); | |
$client->setAuthConfig($credentials_file); | |
$client->setApplicationName(APP_NAME); | |
$client->setScopes([SCOPE]); | |
$service = new Google_Service_Calendar($client); | |
$id = 'event-id'; | |
$event = $service->events->get('primary',$id); | |
$attendeeNew = new Google_Service_Calendar_EventAttendee(); | |
$attendeeNew->setEmail('[email protected]'); | |
$attendeeNew->setResponseStatus('accepted'); | |
$attendeeNew->setOrganizer(true); | |
$attedess = $event->getAttendees(); | |
array_push($attedess,$attendeeNew); | |
$event->setAttendees($attedess); | |
$updatedEvent = $service->events->update('primary', $id, $event); | |
var_dump($updatedEvent->getAttendees()); |
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 | |
include_once 'google-api-php-client/vendor/autoload.php'; | |
$client = new Google_Client(); | |
$application_creds = 'service-account-credentials.json'; | |
$credentials_file = file_exists($application_creds) ? $application_creds : false; | |
define("SCOPE",Google_Service_Calendar::CALENDAR); | |
define("APP_NAME","Google Calendar API PHP"); | |
$client->setAuthConfig($credentials_file); | |
$client->setApplicationName(APP_NAME); | |
$client->setScopes([SCOPE]); | |
$service = new Google_Service_Calendar($client); | |
$event = new Google_Service_Calendar_Event(array( | |
'summary' => 'Google I/O 2015', | |
'location' => '800 Howard St., San Francisco, CA 94103', | |
'description' => 'A chance to hear more about Google\'s developer products.', | |
'start' => array( | |
'dateTime' => '2015-12-01T10:00:00.000-05:00', | |
'timeZone' => 'America/Los_Angeles', | |
), | |
'end' => array( | |
'dateTime' => '2015-12-01T10:00:00.000-05:00', | |
'timeZone' => 'America/Los_Angeles', | |
), | |
'attendees' => array( | |
array( | |
'email' => '[email protected]', | |
'organizer' => true | |
), | |
array( | |
'email' => '[email protected]', | |
'resource' => true | |
), | |
), | |
"creator"=> array( | |
"email" => "[email protected]", | |
"displayName" => "Example", | |
"self"=> true | |
), | |
"guestsCanInviteOthers" => false, | |
"guestsCanModify" => false, | |
"guestsCanSeeOtherGuests" => false, | |
)); | |
$calendarId = 'primary'; | |
$event = $service->events->insert($calendarId, $event); | |
printf('Event created: %s', $event->htmlLink); |
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 | |
include_once 'google-api-php-client/vendor/autoload.php'; | |
$client = new Google_Client(); | |
$application_creds = 'service-account-credentials.json'; | |
$credentials_file = file_exists($application_creds) ? $application_creds : false; | |
define("SCOPE",Google_Service_Calendar::CALENDAR); | |
define("APP_NAME","Google Calendar API PHP"); | |
$client->setAuthConfig($credentials_file); | |
$client->setApplicationName(APP_NAME); | |
$client->setScopes([SCOPE]); | |
$service = new Google_Service_Calendar($client); | |
$event = new Google_Service_Calendar_Event(); | |
$event->setSummary('Halloween'); | |
$event->setLocation('The Neighbourhood'); | |
$event->setSummary('Evento creado desde el API') | |
$start = new Google_Service_Calendar_EventDateTime(); | |
$start->setDateTime('2015-12-01T10:00:00.000-05:00'); | |
$event->setStart($start); | |
$end = new Google_Service_Calendar_EventDateTime(); | |
$end->setDateTime('2015-12-02T10:25:00.000-05:00'); | |
$event->setEnd($end); | |
$attendee = new Google_Service_Calendar_EventAttendee(); | |
$attendee->setEmail('[email protected]'); | |
$attendees = array($attendee); | |
$event->setAttendees($attendees); | |
$organizer = new Google_Service_Calendar_EventOrganizer(); | |
$organizer->setEmail('[email protected]'); | |
$organizer->getDisplayName("Full Name"); | |
$event->setOrganizer($organizer); | |
$createdEvent = $service->events->insert('primary', $event); | |
echo "ID => <br>"; | |
echo $createdEvent->getId() . "<br>"; | |
echo "HTML => <br>"; | |
echo $createdEvent->getHtmlLink() . "<br>"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment