在 javascript 中使用 API v3 检索单个日历事件

Retrieve single Calendar Event using API v3 in javascript

我修改了此处找到的脚本 以显示未来 30 天内即将发生的事件的页面,其中总结了每个事件。

我想创建一个 link 将上面页面上的每个事件摘要提供给另一个页面,该页面将显示特定单个事件的更多详细信息。

我似乎无法编写成功获取 eventId 并查询 Google 日历 API 以检索该单个事件的资源的代码。

我提前道歉,因为我正在努力学习 Javascript 所以我怀疑这是我坚持的相当简单的事情。

我相信在 makeApiCall() 函数中我希望更改以以下内容开头的行:

var 请求 = gapi.client.calendar.events.list({

至:

gapi.client.load('calendar', 'v3', 函数 () { var 请求 = gapi.client.calendar.events.get({ 'calendarId' : 用户邮箱, 'eventId': eventIDstr});

我在使用 Google 的 API 资源管理器页面时可以获得有效答案,因此我知道我拥有正确的日历和事件 ID。似乎无法将其应用于正确的 javascript 以获得我正在寻找的结果。

我到处搜索 javascript 的示例,这些示例将使用 API 的 v3 从 Google 日历中检索单个事件的数据,但没有找到任何有用的信息。任何帮助将不胜感激。

提前致谢。

是的,您走在正确的道路上。使用 Events:get. Events provides different flavors of event resources

HTTP 请求

GET https://www.googleapis.com/calendar/v3/calendars/calendarId/events/eventId

如果成功,方法 returns 在响应正文中 event resource

import com.google.api.services.calendar.Calendar;
import com.google.api.services.calendar.model.Event;

// ...

// Initialize Calendar service with valid OAuth credentials
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName("applicationName").build();

// Retrieve an event
Event event = service.events().get('primary', "eventId").execute();

System.out.println(event.getSummary());

您可以立即为您使用 singleEvents=true parameter in the list request to avoid the second call. This will ask the server to do the recurring event 扩展。