2014-04-01 2 views
0

내가 내 캘린더에 이벤트를 추가하려면이 코드를 사용하고 내 Google 캘린더에 표시 : 나는 이벤트 ID를 얻을 수

<?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()); 
} 
?> 

,이 출력됩니다 하지만 브라우저에서 캘린더를 볼 때 절대적으로 아무 것도 없습니다.

답변

0

서비스 계정 달력에서 이벤트를 만들고 있는데 내 대답 here을 확인하십시오.