Google API: 如何增加访问令牌的有效期?

Google API: How to increase access token expiration date?

Google API 有效期为 1 小时,问题是我使用 API 是为了允许用户使用管理 SDK 功能(列出组、添加成员到一组等)

没有人可以在一小时内完成任何一项操作,这需要用户每天多次登录他们的帐户来管理他们的群组。如果您只想使用 Google 对用户进行身份验证,1 小时的到期日期是合适的。

如何增加它或者有什么变通办法吗?我错过了什么吗?

出于安全原因,您无法更改访问令牌的有效期。但是,如果您请求离线访问与令牌关联的范围,您可以 refresh an access token 不提示用户许可。

  • If you use a Google API Client Library, the client object refreshes the access token as needed as long as you configure that object for offline access.
  • If you are not using a client library, you need to set the access_type HTTP query parameter to offline when redirecting the user to Google's OAuth 2.0 server. In that case, Google's authorization server returns a refresh token when you exchange an authorization code for an access token. Then, if the access token expires (or at any other time), you can use a refresh token to obtain a new access token.