在 Android 应用程序中使用 Google 日历 API 的 OAuth2 问题

The issue with OAuth2 of using Google Calendar API in Android app

我已尝试根据此 link 逐步实施 Google 日历 API:https://developers.google.com/google-apps/calendar/quickstart/android

我在 Google 开发者控制台中启用了 OAuth2 和日历 API。

但是出于某些原因,当我想检索日历事件时,我看到了来自 Android Studio Logcat 的以下日志:

出现以下错误: 403 禁止

"code" : 403, 
"errors": [
{
     "domain":"usageLimits",
     "message":"Access Not Configured. The API (Calendar API) is not enabled for your project. Please use the Google Developer Console to update your configuration", 
     "reason":"accessNotConfigured",
     "extendedHelp":"https://console.developers.google.com"
}
],
"message":"Access Not Configured. The API (Calendar API) is not enabled for your project. Please use the Google Developer Console to update your configuration"

你能帮我解决这个问题吗?

如错误消息所示:您必须使用 Google 开发者控制台启用日历 API。考虑 https://developers.google.com/google-apps/calendar/auth 进一步阅读此主题。

Authorizing requests with OAuth 2.0

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

The details of the authorization process, or "flow," for OAuth 2.0 vary somewhat depending on what kind of application you're writing. The following general process applies to all application types:

  1. When you create your application, you register it using the Google Developers Console. Google then provides information you'll need later, such as a client ID and a client secret.
  2. Activate the Google Calendar API in the Google Developers Console. (If the API isn't listed in the Developers Console, then skip this step.)
  3. When your application needs access to user data, it asks Google for a particular scope of access.
  4. Google displays a consent screen to the user, asking them to authorize your application to request some of their data.
  5. If the user approves, then Google gives your application a short-lived access token.
  6. Your application requests user data, attaching the access token to the request.
  7. If Google determines that your request and the token are valid, it returns the requested data.

Some flows include additional steps, such as using refresh tokens to acquire new access tokens. For detailed information about flows for various types of applications, see Google's OAuth 2.0 documentation.