google oauth2 refresh token code example
Example 1: google oauth2 does token change when refresh
The Google Auth server issued Refresh tokens
never expire — that's the whole point of the
refresh tokens. The refresh token will
expire (or I should say become unauthorized) when the user
revokes access to your application.
Example 2: documentation for https://www.googleapis.com/oauth2/v4/token
>>>
>>> client_id = '<the id you get from google>.apps.googleusercontent.com'
>>> client_secret = '<the secret you get from google>'
>>> redirect_uri = 'https://your.registered/callback'
>>>
>>> authorization_base_url = "https://accounts.google.com/o/oauth2/v2/auth"
>>> token_url = "https://www.googleapis.com/oauth2/v4/token"
>>> scope = [
... "https://www.googleapis.com/auth/userinfo.email",
... "https://www.googleapis.com/auth/userinfo.profile"
... ]
>>> from requests_oauthlib import OAuth2Session
>>> google = OAuth2Session(client_id, scope=scope, redirect_uri=redirect_uri)
>>>
>>> authorization_url, state = google.authorization_url(authorization_base_url,
...
...
... access_type="offline", prompt="select_account")
>>> print 'Please go here and authorize,', authorization_url
>>>
>>> redirect_response = raw_input('Paste the full redirect URL here:')
>>>
>>> google.fetch_token(token_url, client_secret=client_secret,
... authorization_response=redirect_response)
>>>
>>> r = google.get('https://www.googleapis.com/oauth2/v1/userinfo')
>>> print r.content