Google api ruby insert_calendar 方法的客户端问题

Google api ruby client issue with the insert_calendar method

我正在为 google 日历 api 使用 google 代码示例。此代码应该使用 google 日历 api 创建一个新日历。我不清楚如何访问 insert_calendar 方法。

有人知道结果变量中的客户端对象来自哪里吗?它来自什么class?

calendar = Google::Apis::CalendarV3::Calendar.new(
  summary: 'calendarSummary',
  time_zone: 'America/Los_Angeles'
)
result = client.insert_calendar(calendar)
print result.id

我不知道如何制作一个新的。当我创建一个新对象时:

client = Google::APIClient.new

然后我在上面调用方法。我没有找到 insert_calendar 方法。谁能告诉我需要实例化什么对象才能使用 insert_calendar 方法?

这是一个简单的问题,但我在寻找如何自己回答这个问题时遇到了很大的问题。

文档页面是 here。看起来它是 Google::Apis::CalendarV3::CalendarService.

的实例方法

由于本文档中的用法不是特别清楚,我转到 Github 上的 google-api-client 源并使用 "search this repository" 工具找到 insert_calendar 的位置已定义。

它在 this file.

通过查看源代码和文档,我可以建议您尝试以下代码(尽管我尚未对此进行验证:

calendar = Google::Apis::CalendarV3::Calendar.new(
  summary: 'calendarSummary',
  time_zone: 'America/Los_Angeles'
)

Google::Apis::CalendarV3::CalendarService.new.insert_calendar(
  calendar: calendar,
  # other options can go here
)