【问题标题】:Updating Google Calendar - Fatal error: Call to undefined function dateTime()更新 Google 日历 - 致命错误:调用未定义的函数 dateTime()
【发布时间】:2016-09-29 20:55:29
【问题描述】:

我正在尝试使用 PHP API 更新 Google 日历。我已成功创建 Google 日历活动并自动获取活动 ID,但是当我尝试更新活动时,我收到此错误:

PHP 致命错误:在第 45 行的 public_html/googleapi/calendarupdate.php 中调用未定义函数 dateTime()。它指的是以下行:

$event->setStart.dateTime($startdatetime);

这是我当前的错误 PHP 代码:

    <?php

header('Content-type: application/json');

require_once __DIR__ . '/google-api-php-client/src/Google/autoload.php';

$summary = $_POST["summary"];
$location = $_POST["location"];
$description = $_POST["description"];
$startdatetime = $_POST["startdatetime"];
$enddatetime = $_POST["enddatetime"];
$clientemail = $_POST["clientemail"];
$privatekey = $_POST["privatekey"];
$useremail = $_POST["useremail"];
$calendarid = $_POST["calendarid"];



$client_email = $clientemail;
$private_key = file_get_contents($privatekey);
$scopes = array('https://www.googleapis.com/auth/calendar');
$user_to_impersonate = $useremail;
$credentials = new Google_Auth_AssertionCredentials(
    $client_email,
    $scopes,
    $private_key,
    'notasecret',                                 // Default P12 password
    'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type
    $user_to_impersonate
);
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion();
}

$service = new Google_Service_Calendar($client);

$event = $service->events->get($useremail, $calendarid);
$event->setSummary($summary);
$event->setLocation($location);
$event->setStart.dateTime($startdatetime);
$event->setStart.timeZone('America/Los_Angeles');
$event->setEnd.dateTime($enddatetime);
$event->setEnd.timeZone('America/Los_Angeles');
$event->setDescription($description);

$updatedEvent = $service->events->update($useremail, $event->getId(), $event);

echo json_encode($updatedEvent);

我的 PHP 代码基于找到的 Google API 文档here。

【问题讨论】:

  • set start date 是一个你需要传递给它一个日期的方法 $event->setStart($date);

标签: php api google-calendar-api


【解决方案1】:

好的,我实际上设法弄清楚了。我只需要换行:

$event->setStart.dateTime($startdatetime);

到这里:

$event->start->setDateTime($startdatetime);

我对结束日期时间做同样的一般事情,除了它说开始的地方,我只是把结束。刚刚对其进行了测试,并且效果很好。可以找到帮助我的网站here。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-13
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多