2012-06-06 132 views
1

這是一個新手的問​​題,我不習慣谷歌API尚未PHP谷歌日曆API - 更新事件


嗨,

我使用谷歌提供的代碼(https://developers.google.com/google-apps/calendar/downloads ),這些例子(最初是因爲它看起來更新)。

我正在成功檢索日曆,例如「calendar/simple.php」所示(OAuth2設置正確)。

在那之後,我做這個和它的工作原理(這是一個非必要的代碼,只是爲了檢查,如果事件能夠正確檢索沒有任何錯誤):

$test = $cal->events->get("[email protected]","longeventcodegivenbygoogle"); 

現在,我希望能夠設置特定事件的某些值。

$event = new Event(); 
$event->setLocation('Somewhere'); 
$test = $cal->events->update("[email protected]","longeventcodegivenbygoogle",$event); 

但它給我:

(!) Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling PUT https://www.googleapis.com/calendar/v3/calendars/[email protected]/events/longeventcodegivenbygoogle?key=myapikey: (400) Required' in C:\wamp\www\test\Gapi3\src\io\apiREST.php on line 86 
(!) apiServiceException: Error calling PUT https://www.googleapis.com/calendar/v3/calendars/[email protected]/events/longeventcodegivenbygoogle?key=myapikey: (400) Required in C:\wamp\www\test\Gapi3\src\io\apiREST.php on line 86 

我該怎麼辦錯了嗎?

感謝您的幫助。

回答

3

真正的解決方案是通過克勞迪奧凱魯比諾與事件類的調用來創建事件對象給出。

默認情況下,get()不會返回一個事件對象,而是一個數組。

$event = new Event($cal->events->get("[email protected]","longeventcodegivenbygoogle")); 
$event->setLocation('Somewhere'); 
$updated = new Event($cal->events->update("[email protected]", $event->getId(), $event)); 

如果不創建()或get()方法將無法正常工作,因爲它正在由這些調用返回一個簡單數組由更新提供的陣列事件。

+1

你似乎需要使用新的Google_Event – Enkay

3

爲了更新事件,您先檢索它,然後更改其屬性的值,而不是實例化一個新的屬性。

嘗試以下代碼:

$event = $cal->events->get("[email protected]","longeventcodegivenbygoogle"); 
$event->setLocation('Somewhere'); 
$updated = $cal->events->update("[email protected]", $event->getId(), $event);