Answer the question
In order to leave comments, you need to log in
How to add a task to google calendar?
Good afternoon, tell me how to add an event to the google calendar using a php script?
error_reporting(E_ALL);
require_once 'google-api-php-client/Google_Client.php';
require_once 'google-api-php-client/Google_CalendarService.php';
$client = new Google_Client();
$client->setApplicationName("Calendar");
$client->setClientId('exampleID');
$client->setClientSecret('exampleSecret');
$client->setRedirectUri('http://www.example.ru/event.php');
$client->setDeveloperKey('exampleKey');
$cal = new Google_CalendarService($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken())
{
$event = new Google_Event();
$event->setSummary('summary');
$event->setDescription('summary');
$event->setLocation('location');
$start = new Google_EventDateTime();
$start->setDateTime('Sorderdate');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('Eorderdate');
$event->setEnd($end);
$createdEvent = $cal->events->insert('Calendar ID COme Here', $event);
echo 'событие создано';
}
else
{
$authUrl = $client->createAuthUrl();
print "<hr><br><font size=+2><a href='$authUrl'>подключиться</a></font>";
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question