您可以使用刷新令牌。可以通过刷新令牌来更新访问令牌。可以按以下方式检索此刷新令牌。首先,需要以下信息来检索refreshtoken。
- 客户编号
- 客户机密
- 重定向URI
- 范围
从您的问题来看,您似乎已经具有访问令牌。因此,我认为您具有上述信息。
接下来,使用上述信息,它检索您的应用程序可用来获取访问令牌的授权代码。请按如下所示创建一个URL,并将其放入您的浏览器,然后单击以授权。我总是使用此URL检索代码并检索刷新令牌。可以通过包含access_type
= offline来检索刷新令牌。
https://accounts.google.com/o/oauth2/auth?response_type=pre&approval_prompt=force&access_type=offline&client_id=### your_client_ID ###&redirect_uri=### edirect_uri ###&scope=### scopes ###
授权码显示在浏览器上或显示为URL。您可以使用该代码检索刷新令牌。
以下2个示例是python脚本。
检索刷新令牌:
import requestsr = requests.post( 'https://accounts.google.com/o/oauth2/token', headers={'content-type': 'application/x-www-form-urlenpred'}, data={ 'grant_type': 'authorization_pre', 'client_id': '#####', 'client_secret': '#####', 'redirect_uri': '#####', 'pre': '#####', })使用刷新令牌检索访问令牌:
import requestsr = requests.post( 'https://www.googleapis.com/oauth2/v4/token', headers={'content-type': 'application/x-www-form-urlenpred'}, data={ 'grant_type': 'refresh_token', 'client_id': '#####', 'client_secret': '#####', 'refresh_token': '#####', })您可以在此处查看详细信息。https://developers.google.com/identity/protocols/OAuth2WebServer



