从Google公共日历中显示即将举办的活动的最简单方法是什么?

时间:2015-04-16 07:15:46

标签: ruby-on-rails ruby calendar google-calendar-api

我在网站上有一个公共日历。我需要在头版上显示即将发生的事件。

花了一整天的时间我就要放弃了。 Google正在停用较旧的API,没有任何文档或任何内容。我正在解析RSS提要:

http://www.google.com/calendar/feeds/.../public/basic?futureevents=true

从XML中抓取feed/entry/updatefeed/entry/title。我在某处读到futureevents将显示即将发生的事件。但是我得到了旧活动的清单。

好的,然后我尝试使用API​​ V3 https://developers.google.com/google-apps/calendar/v3/reference/events/list

以下是我得到的回应:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

我跳过更多的箍并安装了他们的ruby code sample,因为我需要这个用于Rails网站。

它有点奏效,但需要用户确认访问自己的日历。我不需要那个。此外,似乎认证仅在一天内有效。

上述日历是公开的。它使用xml和ical feed在网站上的iframe中显示。我所需要的只是解析即将发生的事件,以便在首页上显示它们。

没有授权和其他荒谬的事情,这样做的方法是什么?

2 个答案:

答案 0 :(得分:0)

使用此向导创建新的API项目:https://console.developers.google.com/start/api?id=calendar然后单击“创建新密钥”(选择服务器密钥)。然后向https://www.googleapis.com/calendar/v3/calendars/ / events?key = {YOUR_API_KEY}请求用您的值替换电子邮件和API密钥。

答案 1 :(得分:0)

//这适合我! JS:

var request = gapi.client.calendar.events.list({
      'calendarId': 'xxx',
      'timeMin': (new Date()).toISOString(),
      'showDeleted': false,
      'singleEvents': true,
      'maxResults': 1,
      'orderBy': 'startTime'
    });
    request.execute(function(resp) {}
相关问题