2016-09-29 43 views
3

我正嘗試使用PHP API更新Google日曆。我已成功創建Google日曆事件並自動獲取事件的ID,但是當我嘗試更新事件時,出現此錯誤:正在更新Google日曆 - 致命錯誤:致電未定義函數dateTime()

PHP致命錯誤:調用未定義的函數dateTime()in public_html /googleapi/calendarupdate.php上線45它是指行:

$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代碼是基於關閉谷歌的API的找到文檔here

+0

設置開始日期是一種您需要傳遞日期的方法$ event-> setStart($ date); – DaImTo

回答

0

好的,我真的設法弄清楚了。我不得不改變線路:

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

這樣:

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

我做同樣的事情一般爲最終日期時間,除非它說開始,我只是把結束。只是測試它,它完美的工作。幫助我的網站可以找到here

相關問題