如何使用JavaScript从Google Calendar(API)获取今天的活动?

时间:2012-05-13 13:43:51

标签: javascript google-calendar-api google-api-client

我是Google Calendar API的新手,我正在尝试的是使用JavaScript从公开的Google日历中显示今天的活动。

我发现了这个resource,但我无法弄清楚如何修改它以便它只输出今天的事件。

任何帮助将不胜感激。感谢。

[编辑]

我找到了解决方案。它不优雅,我相信存在更好的方式。

在我添加的loadCalendar(calendarUrl)函数中:

var tomorrow = new Date();
tomorrow.setTime(tomorrow.getTime() + (1000*3600*24));
query.setMinimumStartTime(dateFormat(Date.now(), "isoDate"));
query.setMaximumStartTime(dateFormat(tomorrow, "isoDate"));

和(不要覆盖start-min和start-max值)我已删除:

query.setFutureEvents(true);

对于dateFormat(),我使用了Date Format 1.2.3

2 个答案:

答案 0 :(得分:2)

查看API:https://developers.google.com/google-apps/calendar/v2/reference#Parameters

您可以设置start-min和start-max参数。

答案 1 :(得分:-1)

AuthSub代理身份验证由需要向Google帐户验证用户身份的Web应用程序使用。网站运营商无需访问日历用户的用户名和密码 - 只需要特殊的AuthSub令牌。有关更多详细信息,请参阅AuthSub文档。

当用户首次访问您的应用程序时,它们尚未经过身份验证。在这种情况下,您需要打印一些文字和一个链接,指导用户访问Google,以验证您访问其日历的请求。 Python Google Data API客户端库提供了一个从CalendarService类生成此URL的函数。下面的代码设置了一个指向AuthSubRequest页面的链接。