0

Hy!
I use google-mail-oauth2-tools but I have a problem:
When I write the verification code the program dead.

Traceback (most recent call last): File "oauth2.py", line 346, in <module> main(sys.argv) File "oauth2.py", line 315, in main print 'Refresh Token: %s' % response['refresh_token'] KeyError: 'refresh_token

Why?

Thank you!

1 Answers1

1

You get this keyerror because there is no refresh_token in the response. If you didn't ask for offline access in your request, there will be no refresh token in the response, only an access token, bearer and token expiry.

kaiseroskilo
  • 1,719
  • 4
  • 21
  • 29
  • Check the `prompt=consent` argument in `flow.authorization_url` here: https://developers.google.com/identity/protocols/OAuth2WebServer. You may also find this answer useful: https://stackoverflow.com/questions/10827920/not-receiving-google-oauth-refresh-token – koopmac Oct 21 '19 at 22:38