Reputation: 2494
I have been retrieving Danish holidays using the Google Calendar Api but suddenly it stopped working.
I would normally just call the URL below using an apikey in the key-parameter for authentication: https://www.googleapis.com/calendar/v3/calendars/da.danish%23holiday%40group.v.calendar.google.com/events?key=AIzaSyAi3_vE6AC1E--9sX3LGjk6lOXh0sSNkr8&timeMin=2020-06-29T00:00:00Z&timeMax=2020-07-06T00:00:00Z&singleEvents=true&maxResults=9999
But now I am getting the follow error:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
I tried generating another APIKey but with the same result.
Any ideas why?
Upvotes: 1
Views: 2293
Reputation: 19349
You don't need to authorize your request in order to access a public Calendar (anyone can access it, after all), so an API key can be used for that.
While this might change in the future, and while OAuth is the recommended way to access the API, this is the current product behaviour.
The reason you were getting a 401 was because of this bug, which got fixed a few hours later:
Upvotes: 2
Reputation: 14
It appears that Google now requires OAuth2 clients to be set up even for public calendars like the holidays calendar:
Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.
I used Google's OAuth2 playground to set up access and refresh tokens while in development.
The scope is:
https://www.googleapis.com/auth/calendar.readonly
After that, it would be necessary to set up an OAuth client when a project goes to production.
UPDATE
It was Google's issue. API Keys are working again.
Upvotes: -1