<?php
require_once 'api-php/src/apiClient.php';
require_once 'api-php/src/contrib/apiCalendarService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Google Calendar PHP Starter Application");
$client->setClientId('myClientID');
$client->setClientSecret('myClientsecret');
$client->setRedirectUri('mypage');
$client->setDeveloperKey('mykey');
$cal = new apiCalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$calList = $cal->calendarList->listCalendarList();
print "********** ma connexion est OK ******************<br>";
//******************************************************* TEST ****
$event = new Event();
$event->setSummary('titre de l'evenement');
$event->setLocation('La Rochelle');
$start = new EventDateTime();
$start->setDateTime('2012-07-05T10:00:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2012-07-05T13:25:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('mymail');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $service->events->insert( $client, $event);
echo $createdEvent->getId();
$_SESSION['token'] = $client->getAccessToken();
}
else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
?>
Hello,
I try to insert an event into google calendar.
I use the basic script.
<?php
require_once 'api-php/src/apiClient.php';
require_once 'api-php/src/contrib/apiCalendarService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Google Calendar PHP Starter Application");
$client->setClientId('myClientID');
$client->setClientSecret('myClientsecret');
$client->setRedirectUri('mypage');
$client->setDeveloperKey('mykey');
$cal = new apiCalendarService($client);
$service = new apiCalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$calList = $cal->calendarList->listCalendarList();
print "********** ma connexion est OK ******************<br>";
//******************************************************* TEST ****
$event = new Event();
$event->setSummary('titre de l'evenement');
$event->setLocation('La Rochelle');
$start = new EventDateTime();
$start->setDateTime('2012-07-05T10:00:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2012-07-05T13:25:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('mymail');
$attendees = array($attendee1);
$event->attendees = $attendees;
$createdEvent = $service->events->insert( $client, $event);
$createdEvent = $service->events->insert('primary', $event);