Google日历API v3插入事件

问题描述:

我很难理解Google日历API的插入过程。我有他们在他们的例子中给出的代码,但它在我使用它时不起作用,页面绘制一个空白(如果我在它下面回显文本不显示)。这里是页面我指的是一个链接: https://developers.google.com/google-apps/calendar/v3/reference/events/insertGoogle日历API v3插入事件

这里是代码:

$event = new Event(); 
$event->setSummary('Appointment'); 
$event->setLocation('Somewhere'); 
$start = new EventDateTime(); 
$start->setDateTime('2011-06-03T10:00:00.000-07:00'); 
$event->setStart($start); 
$end = new EventDateTime(); 
$end->setDateTime('2011-06-03T10:25:00.000-07:00'); 
$event->setEnd($end); 
$attendee1 = new EventAttendee(); 
$attendee1->setEmail('attendeeEmail'); 
// ... 
$attendees = array($attendee1, 
       // ... 
      ); 
$event->attendees = $attendees; 
$createdEvent = $service->events->insert('primary', $event); 

echo $createdEvent->getId(); 

从我的理解,我想用我的谷歌日历代码来替换'primary'。我已经这样做了,并用日历所有者的电子邮件地址替换了'attendeeEmail',删除了额外的逗号,并且我没有收到任何回复。引用页面链接到“不推荐使用的代码”,所以我不确定我正在使用的是最新的示例。

有没有我可以参考的工作示例?或者我在做什么有什么问题?任何意见,不胜感激。

最后的问题:这是所有链接在“事件 - >插入”目录下。还有一个'Calendars - > Insert'和一个'CalendarList - > Insert'目录。 'CalendarList - > Insert'表示我要使用此代码插入到用户日历中:

$calendarListEntry = new CalendarListEntry(); 
$calendarListEntry->setId("calendarId"); 

$createdCalendarListEntry = $service->calendarList->insert($calendarListEntry); 

echo $createdCalendarListEntry->getSummary(); 

我应该使用它吗?如果是的话,我在哪里可以找到一个示例或教程来使用它? (我要如何插入的startDateTime,endDateTime,时区等)

解决 - 这是正确的代码:

$event = new Google_Service_Calendar_Event(); 
$event->setSummary('Appointment'); 
$event->setLocation('Somewhere'); 
$start = new Google_Service_Calendar_EventDateTime(); 
$start->setDateTime('2011-06-03T10:00:00.000-07:00'); 
$event->setStart($start); 
$end = new Google_Service_Calendar_EventDateTime(); 
$end->setDateTime('2011-06-03T10:25:00.000-07:00'); 
$event->setEnd($end); 
$attendee1 = new Google_Service_Calendar_EventAttendee(); 
$attendee1->setEmail('email'); 
// ... 
$attendees = array($attendee1 
       //, ... 
      ); 
$event->attendees = $attendees; 
$createdEvent = $service->events->insert('primary', $event); 
echo $createdEvent->getId(); 

您可以使用“主”字符串直接,没有必要用电子邮件代替它,如果你想要访问登录用户的主日历。但是,在任何地方插入任何东西之前,您需要正确进行身份验证。请按照这里入门:https://developers.google.com/google-apps/calendar/instantiate还有一个php代码示例。

还有一些对SO刀片的许多其他工作的样本,比如这里:Create Simple Google Calendar Event in PHP

关于您的最后一个问题,CalendarList集是向你表明你的身份验证的用户添加到他们的日历清单中的日历( Web UI中的左侧面板)。它不以任何方式处理事件。为此,你需要坚持事件收集。

+0

我的身份验证工作正常,我可以做一些事情,比如列出日历,但这是插入部分不起作用。我经历了很多示例,并且迄今为止它们都没有工作过,就像在你使用'$ cal = new Google_CalendarService($ client)的链接中那样';'我只能获得'$ service = new Google_Service_Calendar($客户);'去工作。不工作的特定部分是'$ event = new Event();'并且我已将其更改为'$ event = new Google_Event();'仍然没有任何结果。 – 2014-10-06 15:03:38

+0

是的,我明白你的意思了。如有疑问,请查看源代码;)https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Calendar.php新的Google_Service_Calendar($ client)听起来正确,对于该事件的名称是:Google_Service_Calendar_Event – luc 2014-10-06 22:22:18

+0

那也是xD Google_Service_Calendar的工作,但日期/时间不是,但我相信我可以从那里弄明白,谢谢你的帮助! – 2014-10-07 15:28:16