【发布时间】:2021-12-08 02:36:04
【问题描述】:
我将 google API 用于个人项目,因此我的应用没有通过 google 验证。
我自己使用的是 this 代码示例,登录时会生成一个 token.json 文件。一切正常,每次我发出请求(每 10 分钟)访问令牌都会或多或少地发生变化。
一周后,请求失败。在 token.json 文件中的 "expiry" 字段之后整整一周。
google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.', {'error': 'invalid_grant', 'error_description': 'Token has been expired or revoked.'})
如果我理解正确,谷歌也应该更新refresh_token,但这并没有发生。
我认为这部分会处理获取新的刷新令牌:
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request()) ## HERE ##
else:
这可能是由于我的应用未通过验证造成的吗?我没有找到任何关于refresh_token 行为的信息。
【问题讨论】:
标签: python google-api google-oauth google-api-python-client