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 (将#修改为@)