Share private Google calendar via api

2019-07-21 00:03发布

I am trying to access a calendar hosted on google via my node application however I am unable to query it via the given api due to my calendar needing authorisation.

How would I go about disabling this/making the calendar accessible to my application?

Here is my api query: https://www.googleapis.com/calendar/v3/calendars/heathwallace.com_gpupieshkuc85dd832m9gjrh9g@group.calendar.google.com

And this is the response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

2条回答
叛逆
2楼-- · 2019-07-21 00:17

If you check the documentation Calendars: get for example: you will notice it states

Requires authorization

Now normally if you set something to public you will be able to retrieve it using a public API key. I took one of my test calendars set it to public then tried to retrieve it using a public API key. (both key and calendar name have been changed)

https://www.googleapis.com/calendar/v3/calendars/tfaf72h2ubfsftl3h4l5qd87s@group.calendar.google.com?key=AIzaSyBBH88dIQPjcl5nIG-n1mmuQ12J7HThDBL

results are

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

Conclusion: You must be authenticated to retrieve data. Either using OAuth2 or a service account. Normally I would suggest you use a service account and grant it access to the Calendar in question. I would not use a service account with JavaScript due to security issues, so I cant help you with that.

Answer to your question you must be authenticated to see a calendar. there is no way around that.

查看更多
▲ chillily
3楼-- · 2019-07-21 00:22

You can easily do this actually (no Oauth required). The piece of magic is to create a developer key in the developer console console.developers.google.com (in the APIs & Auth -> Credentials -> Public Access Key -> Key for server app)

Make sure to have the calendar API enabled in the console again (APIs & Auth -> Apis)

GET https://www.googleapis.com/calendar/v3/calendars/heathwallace.com_gpupieshkuc85dd832m9gjrh9g%40group.calendar.google.com/events?key={YOUR_API_KEY}

I've just successfully retrieved your calendar that way.

查看更多
登录 后发表回答