好吧,既然没有人回答,我决定开始研究 Google 日历 API 的非 PHP 文档,特别是 .NET 的东西和原始协议的一些内容。而且你不知道吗...
如果您访问 .NET 文档,它会提到很酷的新功能,特别是如何为经过身份验证的用户创建新的非主日历以及如何将事件添加到非主日历。
当然,该文档在 PHP 领域中没有出现,并且似乎没有一对一的关联。对于新日历的创建,我首先尝试了一些明显的东西,然后,为了破产,尝试了一些不太明显但有效的东西。我想我会分享一下,以防无线电沉默的原因是没有人知道答案,但肯定想知道。
要创建新日历:
这有两个关键:
您必须使用相同的方法来添加日历事件,即insertEvent()
您必须在方法中设置发布 URL,否则将转到默认提要 URL。
此示例检查 App Calendar 是否已存在,如果不存在,则创建它:
//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)
,棘手的部分是获取日历的 URL。与“拥有的日历”路径不同,特定的日历不仅包含特定于用户的信息,而且还包含某种哈希查找 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>";
感谢任何阅读我的问题并对此进行任何思考的人。如果有人知道收紧上述代码的方法(也许我不需要两个循环?)我很想得到反馈。