Questo è un enorme dolore nel culo - ma alla fine ho funzionato per creare almeno degli eventi.
Scaricare il più recente zip API di Google PHP e caricarlo nella cartella include sul server web. Utilizza Google API Console per configurare un client API. Assicurati di impostare l'URL di reindirizzamento come uguale all'URL della tua pagina, in modo da reindirizzare a se stesso.
Inizialmente ho impostato alcune variabili per i dettagli dell'evento, è possibile creare un modulo che le inserisca se lo si desidera.
Ecco il mio codice:
<?php
$jobname = "BINGO";
$joblocation = "Your mums house";
$jobdescription = "An interview with a dog.";
$startofjob = "2013-12-20T17:00:00.000+00:00"; //datetimes must be in this format
$endofjob = "2013-12-20T18:00:00.000+00:00"; // YYYY-MM-DDTHH:MM:SS.MMM+HH:MM
//So that's year, month, day, the letter T, hours, minutes, seconds, miliseconds, + or -, timezoneoffset in hours and minutes
include('google-api-php-client/src/Google_Client.php');
include('google-api-php-client/src/contrib/Google_CalendarService.php');
session_start();
$client = new Google_Client();
$client->setApplicationName('doesntmatter-whateveryouwant');
$client->setClientId('yourclientid');
$client->setClientSecret('yourclientsecret');
$client->setRedirectUri('yourredirecturl-setingoogleconsole');
$client->setDeveloperKey('yourdeveloperkey');
$cal = new Google_CalendarService($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$event = new Google_Event();
$event->setSummary($jobname);
$event->setDescription($jobdescription);
$event->setLocation($joblocation);
$start = new Google_EventDateTime();
$start->setDateTime($startofjob);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($endofjob);
$event->setEnd($end);
$createdEvent = $cal->events->insert('[email protected]', $event);
echo $createdEvent->id;
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
?>
Segui collegamento sotto. https://stackoverflow.com/questions/43658751/add-events-to-calendar-programmatically?answertab=votes#tab-top –
Segui il link sottostante. https://stackoverflow.com/questions/43658751/add-events-to-calendar-programmatically?answertab=votes#tab-top –