Skip to content

Instantly share code, notes, and snippets.

@whatnick
Created June 13, 2019 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatnick/666e03d25286852235750d269ed0eda8 to your computer and use it in GitHub Desktop.
Save whatnick/666e03d25286852235750d269ed0eda8 to your computer and use it in GitHub Desktop.
Integration between PyDrive and Flask-Dance
oauth_token = session['google_oauth_token']
from oauth2client.client import OAuth2Credentials
from datetime import datetime
expirty_str = str(datetime.fromtimestamp(oauth_token['expires_at']))
with flask_app.app_context():
token_data = {
'access_token' : oauth_token['access_token'],
'token_expiry' : expirty_str,
'user_agent' : 'PyDrive Automation',
'refresh_token' : None,
'invalid' : False,
'client_id' : flask_app.config['GOOGLE_OAUTH_CLIENT_ID'],
'client_secret': flask_app.config['GOOGLE_OAUTH_CLIENT_SECRET'],
'redirect_uris': [redir_url],
'auth_uri': 'https://accounts.google.com/o/oauth2/auth',
'token_uri': 'https://accounts.google.com/o/oauth2/token'
}
gauth.credentials = OAuth2Credentials.from_json(json.dumps(token_data))
logging.info("PyDrive is now authenticated")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment