Google API 访问令牌含义

Google API access token meaning

有人创建了一个使用 Google API 的系统。碰巧我已经使用这个系统几个月来上传文件到G Drive并且效果很好。 但是今天我在下面的字符串中意识到有一个到期日期(直到今天才更新)阻止上传文件。我的理解是每次我的代码请求 API 访问时都会生成一个令牌,但这显示了相同的 access_token 和刷新令牌以及到期日期。我试图在没有清晰理解的情况下阅读官方文档。你能简单解释一下我应该怎么想吗,并提示我应该如何重新生成所需的令牌。

{"access_token": "xxx", "client_id": "yyy", "client_secret": "nnn", "refresh_token": "bbb", "token_expiry": "2021-02-24T05:33:24Z", "token_uri": "https://accounts.google.com/o/oauth2/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "xxx", "expires_in": 3599, "scope": "https://www.googleapis.com/auth/drive", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/drive"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": true, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}

我的理解是,因为我们需要多个参数来访问 Google API,其中包括身份验证等。因为有多个步骤来验证 API 调用,如果他们成功了,我们会得到一个 access_token,它现在表示所有过程(或身份验证等)都成功了,现在 access_token 就是证明。所以在那之后,将只检查令牌(直到其到期日期)并且该过程将在到期后重复。

The authorization sequence begins when your application redirects a browser to a Google URL; the URL includes query parameters that indicate the type of access being requested. Google handles the user authentication, session selection, and user consent. The result is an authorization code, which the application can exchange for an access token and a refresh token.

The application should store the refresh token for future use and use the access token to access a Google API. Once the access token expires, the application uses the refresh token to obtain a new one.

更多详情Here