Đây là một nỗi đau khổng lồ trong ass - nhưng cuối cùng tôi đã nhận được nó làm việc để tạo ra các sự kiện ít nhất.
Tải xuống mã zip API PHP gần đây nhất của Google và tải nó lên thư mục bao gồm của bạn trên máy chủ web của bạn. Sử dụng Google API Console để thiết lập ứng dụng khách API. Đảm bảo bạn đặt url chuyển hướng của mình giống với url của trang - do đó, nó chuyển hướng đến chính nó.
Ban đầu, tôi chỉ đặt một số biến cho chi tiết sự kiện, bạn có thể tạo biểu mẫu để đẩy các biến này vào nếu bạn muốn.
Dưới đây là mã của tôi:
<?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>";
}
?>
Thực hiện theo bên dưới liên kết. https://stackoverflow.com/questions/43658751/add-events-to-calendar-programmatically?answertab=votes#tab-top –
Làm theo liên kết bên dưới. https://stackoverflow.com/questions/43658751/add-events-to-calendar-programmatically?answertab=votes#tab-top –