13

我想使用 Google 的 REST API 访问公共日历。

Google 的日历 API 建议我需要一个 OAuth 令牌才能访问日历:

https://developers.google.com/google-apps/calendar/auth

但是,我正在访问公共日历并且正在从服务器执行此操作,因此不能/不应该要求用户进行身份验证。

我正在使用 node.js api:

googleapis
  .discover('calendar', 'v3').execute(function(err, client) {
    client.calendar.calendars.get({ calendarId: '***@group.calendar.google.com' })
      .execute(function (err, response) {
        console.log('response from google', response);
      });
  });

这将返回“您的客户发出了格式错误或非法的请求。这就是我们所知道的。”

调用.withApiKey('***')after.calendars.get()返回相同的错误。

有什么建议么?

4

2 回答 2

16

哦,来吧伙计们!只要日历设置为公开,您就可以在没有 OAuth 的情况下获取数据,而无需用户登录!我自己测试过。

$.ajax({
  url:"https://www.googleapis.com/calendar/v3/calendars/" + cal_id + "/events?key=" + api_key,
  success: function(data) {
    console.log(data);
  }
    });

去尝试一下。

文档在这里https://developers.google.com/google-apps/calendar/v3/reference/events/list#examples

于 2016-10-11T19:42:20.963 回答
13

正如文档所述不止一次

对 Google Calendar API 的所有请求都必须由经过身份验证的用户授权。

因此,如果您想使用谷歌日历 API,您需要经过身份验证的用户。这可以使用Passport.jsPassport-google-oauth等模块轻松实现。

但是,如果您可以暂时搁置 API 并

  • 日历是公开的
  • 你想要只读权限

您可以轻松获取公共地址并通过 ical、xml 或 html 使用日历。看看英国假期公共日历:http: //imgur.com/UGjPtqp

您可以通过以下方式公开访问数据:

这个时候,用node去获取这样的资源,得到你想要的数据就很简单了。

于 2013-08-18T21:09:47.020 回答