Google 日历 APIKey 不再工作

Google Calendar APIKey not working anymore

我一直在使用 Google 日历 Api 检索丹麦假期,但它突然停止工作了。

我通常只调用下面的 URL 在密钥参数中使用 apikey 进行身份验证: 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

但现在我收到以下错误:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "authError",
    "message": "Invalid Credentials",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Invalid Credentials"
 }
}

我尝试生成另一个 APIKey,但结果相同。

知道为什么吗?

看来Google now requires OAuth2 clients to be set up even for public calendars喜欢节假日日历:

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.

我在开发过程中使用 Google's OAuth2 playground 设置访问和刷新令牌。

范围是:

https://www.googleapis.com/auth/calendar.readonly

之后,在项目投入生产时需要设置 OAuth 客户端。

更新

这是Google的问题。 .

您不需要 OAuth 即可访问 public 日历,您遇到的行为是由错误引起的。

您无需授权您的请求即可访问 public 日历(毕竟任何人都可以访问它),因此可以使用 API 密钥。

虽然这在未来可能会发生变化,并且虽然 OAuth 是访问 API 的推荐方式,但这是当前的产品行为。

您收到 401 的原因是因为这个错误,几个小时后修复了该错误: