好吧,因为没有人回答,我决定开始讨论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