2009-02-17 23 views
3

我試圖插入一個新事件到谷歌日曆,我可以用下面做精非默認的谷歌日曆:我如何插入使用Zend/PHP

$sname = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar 
$client = Zend_Gdata_ClientLogin::getHttpClient($userName,$password,$sname); 
$service = new Zend_Gdata_Calendar($client); 

$event = $service->newEventEntry(); 
$event->title = $service->newTitle($name); 
$event->when = array($when); 
$newEvent = $service->insertEvent($event); 

然而,這將只能插入默認日曆。我正嘗試使用insertEvent的URI參數來獲取我需要去的地方:

$uri = "http://www.google.com/calendar/feeds/default/[email protected]/private/full"; 
$newEvent = $service->insertEvent($event, $uri); 

這沒有奏效。我試過編碼和解碼URI,這給了我不同的錯誤信息,但我無法得到這個工作。我幾個小時一直在Google上搜索解決方案,但沒有運氣。誰能幫忙?

謝謝。 - 戴夫

回答

3

我一直在爲此奮鬥一段時間,終於找到了工作。這不是很好包裹,但這是我正在尋找的答案

首先你必須得到日曆ID。如果您進入日曆並點擊名稱旁邊的向下箭頭圖標,則會看到「日曆設置」選項。選擇該菜單項。在底部附近,您將看到日曆地址。這將需要時間來找到日曆ID,它會是這個樣子

(日曆ID:[email protected]

你想[email protected]

在路上我會想在PHP中獲得這個,但現在我可以硬編碼。於是我一個變量設置爲這個

$calendar_user = '[email protected]'; 

當檢索你會SETUSER這樣

$gdataCal = new Zend_Gdata_Calendar($client); 
$query = $gdataCal->newEventQuery(); 
$query->setUser($calendar_user); 

但是當你添加事件,你不能這樣做,你必須使用$ calendar_user點在哪裏事件你插入事件。

因此,這裏是完整的代碼

$calendar_user = '[email protected]'; 
$user = '[email protected]'; 
$pass = 'mygooglecalendarpassword'; 
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar 
$client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,$service); 

$gc = new Zend_Gdata_Calendar($client); 
$newEntry = $gc->newEventEntry(); 
$newEntry->title = $gc->newTitle("mytitle"); 
$newEntry->where = array($gc->newWhere("meeting place")); 

$newEntry->content = $gc->newContent("Meeting description"); 
$newEntry->content->type = 'text'; 

$when = $gc->newWhen(); 
$when->startTime = "{'2012-06-28'}T{'10:00'}:00.000{'-08'}:00"; 
$when->endTime = "{'2012-06-28'}T{'11:00'}:00.000{'-08'}:00"; 
$newEntry->when = array($when); 

$createdEvent = $gc->insertEvent($newEntry, "http://www.google.com/calendar/feeds/".$calendar_user."/private/full"); 

現在,我希望這是有幫助的。我告訴你,我花了太長時間才弄清楚這一點,但我不是世界上最聰明的人。

相關問題