2014-04-01 69 views
0

我使用這個代碼將事件添加到我的日曆:使用谷歌日曆API來創建一個事件,但沒有出現在我的谷歌日曆

<?php 
set_include_path(get_include_path() . PATH_SEPARATOR . 'lib/google-api-php-client-master/src'); 
require_once 'lib/google-api-php-client-master/src/Google/Client.php'; 
require_once 'lib/google-api-php-client-master/src/Google/Service/Calendar.php'; 
$client = new Google_Client(); 
$client->setApplicationName("Calendar"); 
$scopes = array('https://www.googleapis.com/auth/prediction', 'https://www.googleapis.com/auth/calendar'); 
$service_account_name='[email protected]'; 
$key_file_location='lib/myKey.p12'; 
$key = file_get_contents($key_file_location); 
$auth_credentials = new Google_Auth_AssertionCredentials($service_account_name, $scopes, $key); 
$client->setAssertionCredentials($auth_credentials); 
$client->setClientId('xxxx.apps.googleusercontent.com'); 
$service = new Google_Service_Calendar($client); 

try { 

$event = new Google_Service_Calendar_Event(); 
$event->setSummary('Halloween'); 
$event->setLocation('The Neighbourhood'); 
$event->setDescription('rien'); 
$start = new Google_Service_Calendar_EventDateTime(); 
$start->setDateTime('2014-04-02T10:00:00.000-07:00'); 
$event->setStart($start); 
$end = new Google_Service_Calendar_EventDateTime(); 
$end->setDateTime('2014-04-03T10:25:00.000-07:00'); 
$event->setEnd($end); 




$createdEvent = $service->events->insert('primary', $event); 

echo $createdEvent->getId(); 
} 
catch (Exception $ex) 
{ 
    die($ex->getMessage()); 
} 
?> 

我得到的事件ID,它打印出來,但是當我在瀏覽器中查看日曆時 - 完全沒有。

回答

0

它在服務帳戶的日曆中創建活動,請檢查我的回答here