3

我正在尝试在 Google 日历中插入一个新事件,我可以通过以下方式完成:

$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/something@somethingelse.com/private/full";
$newEvent = $service->insertEvent($event, $uri);

这没有奏效。我已经尝试对 URI 进行编码和解码,这给了我不同的错误消息,但我就是无法让它工作。我已经用谷歌搜索解决方案几个小时了,但没有运气。任何人都可以帮忙吗?

谢谢。- 戴夫

4

2 回答 2

4

发现问题:上面的 URI 不起作用:“ http://www.google.com/calendar/feeds/ default /something@somethingelse.com/private/full”;

那里不应该有默认部分。

此外,@ 符号应替换为编码。所以应该是:“ http://www.google.com/calendar/feeds/something%40somethingelse.com/private/full ”;

于 2009-02-19T01:48:43.263 回答
3

我已经为此奋斗了一段时间,终于让它工作了。这不是很好的包装,但这是我正在寻找的答案

首先,您必须获取日历 ID。如果您进入日历并单击名称旁边的向下箭头图标,您将看到日历设置选项。选择该菜单项。在底部附近,您将看到日历地址。需要一点时间才能找到日历 ID,它看起来像这样

(日历 ID:o4g3921hdiaq5p8kdat2l4vgis@group.calendar.google.com)

你想要 o4g39j1hdihq4p8kdat2l4vgis@group.calendar.google.com

以后我会想在 php 中得到它,但现在我可以硬编码。所以我为此设置了一个变量

$calendar_user = 'o4g39j1hdihq4p8kdat2l4vgis@group.calendar.google.com';

检索事件时,您将像这样设置用户

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

但是,当您添加事件时,您不能这样做,您必须在插入事件的位置使用 $calendar_user。

所以这里是完整的代码

$calendar_user = 'o4g39j1hdihq4p8kdat2l4vgis@group.calendar.google.com';
$user = 'myemail@yahoo.com';
$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");

现在我希望这会有所帮助。我告诉你我花了很长时间才弄清楚这一点,但我不是世界上最聪明的人。

于 2012-06-29T21:31:54.100 回答