如何解决Google Api ouath 验证,cred.refresh_token 不起作用
当证书失效时,它应该使用 creds.refresh_token 但它不起作用。我必须删除旧的泡菜文件并创建一个新文件。顺便说一下,这是在 repl 上完成的,这里是错误:google.auth.exceptions.RefreshError: ('invalid_grant: Token has been expired or revoked.','{\n "error": "invalid_grant",\n "error_description": "令牌已过期或吊销。"\n}') 这是我的验证流程:
# The file token.pickle stores the user's access and refresh tokens,and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.pickle'):
with open('token.pickle','rb') as token:
creds = pickle.load(token)
# 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())
else:
flow = Flow.from_client_secrets_file('client_secret_4.json',scopes=SCOPES,redirect_uri= 'urn:ietf:wg:oauth:2.0:oob')
auth_url,_ = flow.authorization_url(prompt='consent')
print('Please go to this URL: {}'.format(auth_url))
code = input('Enter the authorization code: ')
flow.fetch_token(code=code)
creds = flow.credentials
with open('token.pickle','wb') as token:
pickle.dump(creds,token)```
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。