好吧,因爲沒有人回答,我決定開始討論Google Calendar API的非PHP文檔,特別是在.NET的東西,只是在原始協議中。而你不知道它...
如果你去到.NET文檔它提到酷新功能,具體如何認證用戶創建新的非主日曆以及如何將事件添加到非主要日曆。
當然,這個文檔在PHP領域沒有出現,並且似乎沒有一對一的關聯。爲了創建新的日曆,我首先嚐試了一些明顯的東西,然後,破產,嘗試了一些不那麼明顯的工作。我想我會分享一下,因爲無線電沉默的原因是沒有人知道答案,但肯定會。
要創建一個新的日曆:
有兩個關鍵是:
你必須使用同樣的方法添加日曆事件,這是insertEvent()
你有在方法中設置發佈的網址,否則這些網址會轉到默認的Feed網址。
此示例檢查,看是否App日曆已經存在,如果沒有,創建它:
//Standard creation of the HTTP client
$gdataCal = new Zend_Gdata_Calendar($client);
//Get list of existing calendars
$calFeed = $gdataCal->getCalendarListFeed();
//Set this to true by default, only gets set to false if calendar is found
$noAppCal = true;
//Loop through calendars and check name which is ->title->text
foreach ($calFeed as $calendar) {
if($calendar -> title -> text == "App Calendar") {
$noAppCal = false;
}
}
//If name not found, create the calendar
if($noAppCal) {
// I actually had to guess this method based on Google API's "magic" factory
$appCal = $gdataCal -> newListEntry();
// I only set the title, other options like color are available.
$appCal -> title = $gdataCal-> newTitle("App Calendar");
//This is the right URL to post to for new calendars...
//Notice that the user's info is nowhere in there
$own_cal = "http://www.google.com/calendar/feeds/default/owncalendars/full";
//And here's the payoff.
//Use the insertEvent method, set the second optional var to the right URL
$gdataCal->insertEvent($appCal, $own_cal);
}
有你有它。下一個目標是將事件插入到該日曆中,而不是插入到默認日曆中。
添加事件,非主日曆
容易的部分,你可能已經猜到的是,你需要重新設置可選的URL,像這樣的:insertEvent($newEvent, $calURL)
,棘手的部分是獲得日曆的網址。與「擁有的日曆」路徑不同,特定的日曆不僅具有用戶特定的信息,還具有某種類型的哈希查找ID。
下面的代碼:
//Set up that loop again to find the new calendar:
$calFeed = $gdataCal->getCalendarListFeed();
foreach ($calFeed as $calendar) {
if($calendar->title->text == "App Calendar")
//This is the money, you need to use '->content-src'
//Anything else and you have to manipulate it to get it right.
$appCalUrl = $calendar->content->src;
}
//.......... Some Assumed MySQL query and results .............
while ($event = $result->fetch_assoc()) {
$title = $event['description'];
//Quick heads up
//This is a handy way of getting the date/time in one expression.
$eventStart = date('Y-m-d\TH:i:sP', strtotime($event['start']));
$eventEnd = date('Y-m-d\TH:i:sP', strtotime($event['end']));
$newEvent = $gdataCal->newEventEntry();
$newEvent->title = $gdataCal->newTitle($title);
$when = $gdataCal->newWhen();
$when->startTime = $eventStart;
$when->endTime = $eventEnd;
$newEvent->when = array($when);
//And at last, the insert is set to the calendar URL found above
$createdEvent = $gdataCal->insertEvent($newEvent, $appCalUrl);
}
echo "<p>".$result->num_rows." added to your Google calendar.</p>";
感謝誰看了我的問題,做了它的任何想法。如果有人知道一種方法來收緊上面的代碼(也許我不需要兩個循環?),我很想獲得反饋。
我刪除了谷歌應用程序引擎標記,因爲我不認爲您正在使用它。 – 2009-10-07 22:37:23