Accessing a public calendar using Google API without requiring a user to log in

雨燕双飞 提交于 2019-12-05 01:10:13

As the documentation states more than once

All requests to the Google Calendar API must be authorized by an authenticated user.

Hence, if you want to use the google calendar API you need an authenticated user. This can be easily achieved using modules like Passport.js and Passport-google-oauth.

However, if you can leave aside the API for a moment and

  • the calendar is public
  • you want read only access

you can easily grab the public address and consume the calendar through ical, xml or html. Have a look at the UK holidays public calendar: http://imgur.com/UGjPtqp

You can access the data publicly from:

At this point, it's trivial to fetch such resources with node and get the data you want.

Oh come on guys! You can fetch data without OAuth without requiring a user to login as long as the calendar is set to be public! I've tested it myself.

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

Just try it.

The documentation is here https://developers.google.com/google-apps/calendar/v3/reference/events/list#examples

Google needs to have an authenticated user, but as it is a public calendar, you shouldn't have to ask your user to authenticate. It's server side, so use your own authentification (or create a google user just for that), and as an authenticated user, you'll have access to that calendar, without asking the real user to authenticate...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!