简体   繁体   English

Google Calendar API v3插入事件

[英]Google Calendar API v3 Insert Event

I am having difficulties understanding the insertion process for the google calendar API. 我在理解Google Calendar API的插入过程时遇到困难。 I have the code they gave in their example, but it is not working when I use it, the page draws a blank (if I echo text below it does not show). 我有他们在示例中提供的代码,但是当我使用它时,它无法正常工作,该页面绘制了一个空白(如果我在下面显示的文字不显示)。 Here is a link to the page I am referring to: https://developers.google.com/google-apps/calendar/v3/reference/events/insert 这是指向我所引用页面的链接: https : //developers.google.com/google-apps/calendar/v3/reference/events/insert

Here is the code: 这是代码:

$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();

From my understanding I am suppose to replace 'primary' with my google calendar code. 据我了解,我想用我的Google日历代码替换'primary' I have done that, and replaced 'attendeeEmail' with the calendar owner email address, removed the extra comma, and I am not getting any response. 我已经做到了,并用日历所有者的电子邮件地址替换了'attendeeEmail' ,删除了多余的逗号,但没有得到任何回应。 The referencing page links to 'deprecated code' so I am unsure if what I am using is the most up to date example. 引用页面链接到“不建议使用的代码”,因此我不确定我使用的是最新示例。

Is there a working example out there that I can reference? 有没有可以参考的工作示例? Or is there something wrong with what I am doing? 还是我的工作有问题? Any advise is greatly appreciated. 任何建议,不胜感激。

Final question: This is all linked under the 'Events -> Insert' directory. 最后一个问题:所有这些都链接在“事件->插入”目录下。 There is also a 'Calendars -> Insert' and a 'CalendarList -> Insert' directory. 还有一个“日历->插入”目录和“日历列表->插入”目录。 The 'CalendarList -> Insert' says that I am to use this code to insert into a users Calendar: “ CalendarList->插入”表示我要使用以下代码插入用户日历:

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

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

echo $createdCalendarListEntry->getSummary();

Should I be using this instead? 我应该改用这个吗? If so where can I find an example or tutorial to do use this? 如果是这样,我在哪里可以找到一个示例或教程来使用它? (How do I insert startDateTime, endDateTime, timeZone, etc) (如何插入startDateTime,endDateTime,timeZone等)

SOLVED - Here is the correct code: 求助-这是正确的代码:

$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();

You can use 'primary' string directly, no need to replace it with email if you want to access the primary calendar of the logged-in user. 您可以直接使用“主”字符串,如果要访问已登录用户的主日历,则无需将其替换为电子邮件。 However, before you can insert anything anywhere, you need to authenticate correctly. 但是,在将任何内容插入任何地方之前,需要正确进行身份验证。 Please follow the getting started here: https://developers.google.com/google-apps/calendar/instantiate There is also a php code sample. 请遵循以下入门指南: https : //developers.google.com/google-apps/calendar/instantiate还有一个php代码示例。

Also there are many other working samples of inserts on SO, for example here: Create Simple Google Calendar Event in PHP 此外,SO上还有许多其他有效的插入示例,例如,在这里: 用PHP创建简单的Google日历事件

As about your final question, CalendarList collection is for showing you calendars that your authenticated users added to the list of their calendars (left panel in the web UI). 关于最后一个问题,CalendarList集合用于向您显示经过身份验证的用户添加到其日历列表中的日历(Web UI的左侧面板)。 It does not serve for working with events in any way. 它不适用于以任何方式处理事件。 For that you will need to stick to events collection. 为此,您将需要坚持事件收集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM