我正在尝试使用 Google 日历 API 将一个非常简单的事件添加到日历中,如果有人能指出我的(可能是显而易见的)问题,我会很高兴。我正在使用在这里找到的代码。我已将代码放在“google-api-php-client/examples.calendar”目录中,其中可以找到一个简单的示例。
<?php
require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_CalendarService.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP Starter Application");
$client->setClientId('');
$client->setClientSecret('');
$client->setRedirectUri('worked.html'); //I made a file called "worked.html" in the same directory that just says "it worked!"
$client->setDeveloperKey('SecretLongDeveloperKey');
$cal = new Google_CalendarService($client);
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
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']);
}
$authUrl = $client->createAuthUrl();
if (!$client->getAccessToken()){
$event = new Google_Event();
$event->setSummary('Halloween');
$event->setLocation('The Neighbourhood');
$start = new Google_EventDateTime();
$start->setDateTime('2012-10-31T10:00:00.000-05:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2012-10-31T10:25:00.000-05:00');
$event->setEnd($end);
$createdEvent = $cal->events->insert('secretLongCalendarId@group.calendar.google.com', $event);
}
echo $createdEvent->getId();
?>
当我访问此脚本时,我收到 404 错误。我试图通过代码并注释掉行以试图找到罪魁祸首 - 它似乎是倒数第二行,它实际上插入了事件。
有什么建议吗?我真的很感激一些建议,因为我似乎连最简单的例子都无法工作。