加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 更新Google日历 – 致命错误:调用未定义的函数dateTime(

发布时间:2020-12-13 16:05:42 所属栏目:PHP教程 来源:网络整理
导读:我正在尝试使用 PHP API更新Google日历.我已成功创建Google日历活动并自动获取活动的ID,但是当我尝试更新活动时,我收到此错误: PHP致命错误:在第45行的public_html / googleapi / calendarupdate.php中调用未定义的函数dateTime().它指的是: $event-setSt
我正在尝试使用 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.

解决方法

好吧,我实际上设法搞清楚了.我只需改变这条线:

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

对此:

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

我对结束日期时间做了同样的一般事情,除非它说开始,我只是结束.只是测试它,它完美地工作.帮助我的网站可以找到here.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读