我正在尝试使用Google日历API版本3(PHP)来管理日历。
我可以轻松地检索有关日历的信息,如日历名称和日历列表,但我在实际"写入"到日历(如添加事件或创建辅助日历)方面并不成功。我在尝试中总是收到以下错误。
有谁能帮忙吗?我在谷歌的文档中到处找,但找不到任何答案。
错误(如果试图发布,而不是检索信息):
致命错误:未捕获异常"apiServiceException",消息为"调用POST时出错"https://www.googleapis.com/calendar/v3/calendars?key=eyfheufheuwehwi:(400)/home/incs/google-api-php-client/src/io/apiREST.php中的无效值:86堆栈跟踪:#0/home/inccs/google-api-php client/src/io/apiREST.php(56):apiREST::decodeHttpResponse(对象(apiHttpRequest)(228):apiServiceResource->__call('sert',Array)#3/home/public_html/gateway/google/index.php
代码(顺便说一下,我的访问密钥是在config.php中设置的,因此有注释的$client行)
require("/home/incs/google-api-php-client/src/apiClient.php");
require("/home/incs/google-api-php-client/src/contrib/apiCalendarService.php");
session_start();
$client = new apiClient();
$client->setApplicationName("Google Calendar PHP Starter Application");
// Visit https://code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_oauth2_redirect_uri');
// $client->setDeveloperKey('insert_your_developer_key');
$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())
{
$calendar = new Calendar();
$calendar->setSummary('calendarSummary');
$calendar->setTimeZone('American/Los_Angeles');
$createdCalendar = $service->calendars->insert($calendar);
$calList = $service->calendarList->listCalendarList();
print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
print "<a class='login' href='$authUrl'>Connect Me!</a>";
}
现在,谷歌的代码示例中有一个错误(我就是在这里粘贴代码的)。在该样本中,需要更正以下内容才能工作:
$calendar->setTimeZone('American/Los_Angeles');
需要更正为
$calendar->setTimeZone('America/Los_Angeles');
然后不会抛出任何错误。