在 Postman 中刷新 Google 驱动器 API 的访问令牌
Refresh access token for Google Drive API in Postman
我正在使用 Google 驱动器 API 来获取我的 google 驱动器上的文件列表。我通过在 google 云平台中获取访问令牌、客户端 ID 和客户端密码来使其正常工作。我的问题是,令牌在 3600 后过期。我试过这个端点,https://www.googleapis.com/oauth2/v4/token
并将其放入请求正文中,
{
"client_id": "client_id",
"client_secret": "client_secret",
"refresh_token": "access_token",
"grant_type": "refresh_token"
}
但只返回
{
"access_token": "new_access_token",
"expires_in": 3552,
"scope": "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive",
"token_type": "Bearer"
}
不刷新令牌寿命。
有什么我遗漏的吗?
我先在邮递员上使用它,这样我才能知道它工作正常。
感谢任何帮助。
访问令牌在设定时间后过期,您需要使用收到的刷新令牌调用请求新的访问令牌。
通常,刷新令牌持续时间更长并且不会在一段时间内过期,而访问令牌的生命周期很短。
此 link 是 Google API 文档:https://developers.google.com/identity/protocols/oauth2/web-server#offline
这是一个非常相似的问题,包含有用的信息和有用的答案:How to generate access token using refresh token through google drive API?
基本上,每次需要时,您都可以从 postman 进行 API 调用以请求新的访问令牌(并在 Postman 中使用它进行您需要进行的调用)
事实证明,您需要从 https://developers.google.com/oauthplayground/ 获取刷新令牌。您还需要从 Google Cloud Platform 授权重定向 uri。感谢您的指导。真的帮了大忙
我正在使用 Google 驱动器 API 来获取我的 google 驱动器上的文件列表。我通过在 google 云平台中获取访问令牌、客户端 ID 和客户端密码来使其正常工作。我的问题是,令牌在 3600 后过期。我试过这个端点,https://www.googleapis.com/oauth2/v4/token
并将其放入请求正文中,
{
"client_id": "client_id",
"client_secret": "client_secret",
"refresh_token": "access_token",
"grant_type": "refresh_token"
}
但只返回
{
"access_token": "new_access_token",
"expires_in": 3552,
"scope": "https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive",
"token_type": "Bearer"
}
不刷新令牌寿命。
有什么我遗漏的吗?
我先在邮递员上使用它,这样我才能知道它工作正常。
感谢任何帮助。
访问令牌在设定时间后过期,您需要使用收到的刷新令牌调用请求新的访问令牌。 通常,刷新令牌持续时间更长并且不会在一段时间内过期,而访问令牌的生命周期很短。
此 link 是 Google API 文档:https://developers.google.com/identity/protocols/oauth2/web-server#offline
这是一个非常相似的问题,包含有用的信息和有用的答案:How to generate access token using refresh token through google drive API?
基本上,每次需要时,您都可以从 postman 进行 API 调用以请求新的访问令牌(并在 Postman 中使用它进行您需要进行的调用)
事实证明,您需要从 https://developers.google.com/oauthplayground/ 获取刷新令牌。您还需要从 Google Cloud Platform 授权重定向 uri。感谢您的指导。真的帮了大忙