1
我試圖使用服務帳戶方法將事件插入到Google日曆中。試圖使用服務帳戶在谷歌日曆中創建事件
我能夠檢索日曆列表。但我無法得到同樣的結果。請查看我的代碼,請幫我解決問題。
<?php
//require_once 'google-api-php-client/src/Google/Client.php';
require_once 'google-api-php-client-master/src/Google/Client.php';
require_once 'google-api-php-client-master/src/Google/Service/Calendar.php';
ini_set('display_errors', 1);
define('CLIENT_ID','XXXXXX');
define('SERVICE_ACCOUNT_NAME','XXXXXXXX');
define('KEY_FILE','C:/xampp/htdocs/sv/key.p12');
$client = new Google_Client();
$client->setApplicationName("SV Temple APP");
//$client->setUseObjects(true); //IF USING SERVICE ACCOUNT (YES)
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/calendar'),
$key));
$client->setClientId(CLIENT_ID);
$cal = new Google_Service_Calendar($client);
$calList = $cal->calendarList->listCalendarList();
print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2014-08-27T10:00:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2011-08-27T10:25:00');
$event->setEnd($end);
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('[email protected]');
$event->attendees = $attendee1;
echo "<pre>";
var_dump($cal);
$createdEvent = $cal->events->insert('primary', $event);
echo $createdEvent->getId();
?>
我越來越像錯誤....
Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events: (400) The specified time range is empty.' in C:\xampp\htdocs\sv\google-api-php-client-master\src\Google\Http\REST.php:79
Stack trace:
#0 C:\xampp\htdocs\sv\google-api-php-client-master\src\Google\Http\REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
#1 C:\xampp\htdocs\sv\google-api-php-client-master\src\Google\Client.php(504): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#2 C:\xampp\htdocs\sv\google-api-php-client-master\src\Google\Service\Resource.php(195): Google_Client- >execute(Object(Google_Http_Request))
#3 C:\xampp\htdocs\sv\google-api-php-client-master\src\Google\Service\Calendar.php(1459): Google_Service_Resource->call('insert', Array, 'Google_Service_...')
#4 C:\xampp\htdocs\sv\test.php(50): Google_Service_Calendar_Events_Resource->insert('primary', Object(Google_Service_Calendar_Event))
#5 {main in C:\xampp\htdocs\sv\google-api-php-client-master\src\Google\Http\REST.php on line 79
「但我無法得到同樣的東西「真的不描述發生了什麼... – 2014-08-27 17:40:36
請現在檢查錯誤的詳細信息... – venkatesh 2014-08-27 17:44:30
您在提問之前是否嘗試搜索錯誤? Duplicate ... – 2014-08-27 17:56:30