【发布时间】:2022-12-12 09:53:51
【问题描述】:
目前我正在使用此处概述的步骤:https://developers.google.com/gmail/api/quickstart/python 以使用 gmail API。但是,我的令牌每周都会过期,我必须重置密码、删除令牌 pickle 文件并重新下载凭据 json。
我正在寻找一种无需人工干预即可重置机密的方法。这可能吗?
有关更多详细信息,代码在看到凭据已过期并尝试刷新时失败:
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
收到错误:google.auth.exceptions.RefreshError: ('invalid_client: Unauthorized', {'error': 'invalid_client', 'error_description': 'Unauthorized'})
这是我通常会转到 API 控制台 -> 重置密码 -> 下载 json 文件 -> 删除 token.pickle 然后重新运行的时间。
我还没有尝试过任何其他 api 方法。我在搜索时发现的大多数事情都涉及获取凭据,而不是重置密码。如果已经有一个 api 方法,我还没有看到它。
【问题讨论】:
标签: python google-api google-oauth gmail-api google-api-python-client