diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2018-12-29 14:52:08 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2018-12-29 14:52:08 -0500 |
| commit | fb24d087de5d0ab893887b48936b12645aa6dc57 (patch) | |
| tree | c8b4a1964e652d09e35ab5339e246e7216039744 | |
| parent | 714f3a8138e6c5e2201a9c6c1fa2f67a360eb0b3 (diff) | |
| download | famille-flask-fb24d087de5d0ab893887b48936b12645aa6dc57.tar.gz | |
save credentials
| -rw-r--r-- | email_helpers.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/email_helpers.py b/email_helpers.py index 487bb7e..de19fe8 100644 --- a/email_helpers.py +++ b/email_helpers.py @@ -1,7 +1,6 @@ from apiclient.discovery import build from apiclient import errors from google.oauth2.credentials import Credentials -#from oauth2client import client, tools from google_auth_oauthlib.flow import InstalledAppFlow import os @@ -30,12 +29,17 @@ def get_gmail_service(): if not os.path.exists(credential_dir): os.makedirs(credential_dir) credential_path = os.path.join(credential_dir, 'news.horel@gmail.com') - credentials = Credentials.from_authorized_user_file(credential_path) - if False: - #flags = argparse.ArgumentParser(parents=[tools.argparser]).parse_args() - #flow = Flow.from_client_secrets_file(CLIENT_SECRET_FILE, scopes=SCOPES) + try: + credentials = Credentials.from_authorized_user_file(credential_path) + except: flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES) credentials = flow.run_console() + to_save = {} + for attr in["token", "refresh_token", "id_token", "token_uri", + "client_id", "client_secret", "scopes"]: + to_save[attr] = getattr(credentials, attr) + with open(credential_path, "w") as fh: + json.dump(to_save, fh) service = build('gmail', 'v1', credentials=credentials) return service |
