3

I see on the documentation that you need to set access_type=offline in order to get refresh token.

I did set this value in OAuth url and I clearly see it properly set along with other parameters. However, I still don't get refresh token back as a response. I copy & pasted OAuth2 related code from this documentation.

user2730464
  • 33
  • 1
  • 4

1 Answers1

8

Is this the first time you are authorizing with the application since you changed the parameter to access_type=offline? You will only retrieve refresh token once when client clicks authorization button to grant you access.

One workaround is to set another parameter approval_prompt=force so that user will always click on authorization button and you can always get refresh token. Otherwise, save refresh token locally so that you don't have to retrieve it again.

JunYoung Gwak
  • 2,967
  • 3
  • 21
  • 35
  • 1
    Please save the refresh token locally and do not repeatedly generate refresh tokens for the same user. Google enforces a token cap for each user. Things will break unexpectedly in weird manner when that happens. – Jason Huang Aug 30 '13 at 02:28
  • 2
    A related and very useful thread, http://stackoverflow.com/questions/10827920/google-oauth-refresh-token-is-not-being-received. I have something like `if DEBUG: flow.params['approval_prompt'] = 'true'` when I am developing locally. – zyxue Aug 22 '15 at 17:22
  • approval_prompt=force no longer works – jjxtra Mar 01 '23 at 13:24