diff --git a/admin_sdk/directory/quickstart.py b/admin_sdk/directory/quickstart.py index 5a9b0680..caf0d994 100644 --- a/admin_sdk/directory/quickstart.py +++ b/admin_sdk/directory/quickstart.py @@ -14,13 +14,13 @@ # [START admin_sdk_directory_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/admin.directory.user'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the emails and names of the first 10 users in the domain. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('admin', 'directory_v1', credentials=creds) diff --git a/admin_sdk/reports/quickstart.py b/admin_sdk/reports/quickstart.py index 29bc20dd..2b6d4d06 100644 --- a/admin_sdk/reports/quickstart.py +++ b/admin_sdk/reports/quickstart.py @@ -14,13 +14,13 @@ # [START admin_sdk_reports_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/admin.reports.audit.readonly'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the time, email, and name of the last 10 login events in the domain. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('admin', 'reports_v1', credentials=creds) diff --git a/admin_sdk/reseller/quickstart.py b/admin_sdk/reseller/quickstart.py index 6fb733d0..316edcd2 100644 --- a/admin_sdk/reseller/quickstart.py +++ b/admin_sdk/reseller/quickstart.py @@ -14,13 +14,13 @@ # [START admin_sdk_reseller_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/apps.order'] def main(): @@ -28,12 +28,11 @@ def main(): and plan name of the first 10 subscriptions managed by the domain. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('reseller', 'v1', credentials=creds) diff --git a/apps_script/quickstart/quickstart.py b/apps_script/quickstart/quickstart.py index 1d3005a0..c8650dea 100644 --- a/apps_script/quickstart/quickstart.py +++ b/apps_script/quickstart/quickstart.py @@ -19,14 +19,14 @@ project, and log the script's URL to the user. """ from __future__ import print_function -import pickle import os.path from googleapiclient import errors from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/script.projects'] SAMPLE_CODE = ''' @@ -46,12 +46,11 @@ def main(): """Calls the Apps Script API. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -61,8 +60,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('script', 'v1', credentials=creds) diff --git a/calendar/quickstart/quickstart.py b/calendar/quickstart/quickstart.py index 192a81ec..67d837dd 100644 --- a/calendar/quickstart/quickstart.py +++ b/calendar/quickstart/quickstart.py @@ -15,13 +15,13 @@ # [START calendar_quickstart] from __future__ import print_function import datetime -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/calendar.readonly'] @@ -30,12 +30,11 @@ def main(): Prints the start and name of the next 10 events on the user's calendar. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -45,8 +44,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('calendar', 'v3', credentials=creds) diff --git a/classroom/quickstart/quickstart.py b/classroom/quickstart/quickstart.py index 3ec54884..35646557 100644 --- a/classroom/quickstart/quickstart.py +++ b/classroom/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START classroom_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/classroom.courses.readonly'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the names of the first 10 courses the user has access to. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('classroom', 'v1', credentials=creds) diff --git a/docs/quickstart/quickstart.py b/docs/quickstart/quickstart.py index 7c08fb0a..0dd687e9 100644 --- a/docs/quickstart/quickstart.py +++ b/docs/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START docs_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/documents.readonly'] # The ID of a sample document. @@ -31,12 +31,11 @@ def main(): Prints the title of a sample document. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -46,8 +45,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('docs', 'v1', credentials=creds) diff --git a/drive/activity-v2/quickstart.py b/drive/activity-v2/quickstart.py index 08cc39e7..292999a5 100644 --- a/drive/activity-v2/quickstart.py +++ b/drive/activity-v2/quickstart.py @@ -14,13 +14,13 @@ # [START drive_activity_v2_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/drive.activity.readonly'] @@ -30,12 +30,11 @@ def main(): Prints information about the last 10 events that occured the user's Drive. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -45,8 +44,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('driveactivity', 'v2', credentials=creds) diff --git a/drive/activity/quickstart.py b/drive/activity/quickstart.py index e1a2c3b1..96a40a0e 100644 --- a/drive/activity/quickstart.py +++ b/drive/activity/quickstart.py @@ -15,13 +15,13 @@ # [START drive_activity_quickstart] from __future__ import print_function import datetime -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/activity'] def main(): @@ -29,12 +29,11 @@ def main(): Prints information about the last 10 events that occured the user's Drive. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -44,8 +43,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('appsactivity', 'v1', credentials=creds) diff --git a/drive/quickstart/quickstart.py b/drive/quickstart/quickstart.py index dd0767c9..6267ff42 100644 --- a/drive/quickstart/quickstart.py +++ b/drive/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START drive_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the names and ids of the first 10 files the user has access to. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('drive', 'v3', credentials=creds) diff --git a/gmail/quickstart/quickstart.py b/gmail/quickstart/quickstart.py index 92986897..5e342669 100644 --- a/gmail/quickstart/quickstart.py +++ b/gmail/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START gmail_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'] def main(): @@ -28,12 +28,11 @@ def main(): Lists the user's Gmail labels. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('gmail', 'v1', credentials=creds) diff --git a/people/quickstart/quickstart.py b/people/quickstart/quickstart.py index e43ec320..dcd52210 100644 --- a/people/quickstart/quickstart.py +++ b/people/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START people_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/contacts.readonly'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the name of the first 10 connections. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('people', 'v1', credentials=creds) diff --git a/sheets/quickstart/quickstart.py b/sheets/quickstart/quickstart.py index c782e563..7dff04ab 100644 --- a/sheets/quickstart/quickstart.py +++ b/sheets/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START sheets_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'] # The ID and range of a sample spreadsheet. @@ -32,12 +32,11 @@ def main(): Prints values from a sample spreadsheet. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -47,8 +46,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('sheets', 'v4', credentials=creds) diff --git a/slides/quickstart/quickstart.py b/slides/quickstart/quickstart.py index fbb4b5a8..e86e2487 100644 --- a/slides/quickstart/quickstart.py +++ b/slides/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START slides_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/presentations.readonly'] # The ID of a sample presentation. @@ -31,12 +31,11 @@ def main(): Prints the number of slides and elments in a sample presentation. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -46,8 +45,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('slides', 'v1', credentials=creds) diff --git a/tasks/quickstart/quickstart.py b/tasks/quickstart/quickstart.py index 564acf6b..fcedfe88 100644 --- a/tasks/quickstart/quickstart.py +++ b/tasks/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START tasks_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/tasks.readonly'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the title and ID of the first 10 task lists. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('tasks', 'v1', credentials=creds) diff --git a/vault/quickstart/quickstart.py b/vault/quickstart/quickstart.py index e586626c..851f51be 100644 --- a/vault/quickstart/quickstart.py +++ b/vault/quickstart/quickstart.py @@ -14,13 +14,13 @@ # [START vault_quickstart] from __future__ import print_function -import pickle import os.path from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request +from google.oauth2.credentials import Credentials -# If modifying these scopes, delete the file token.pickle. +# If modifying these scopes, delete the file token.json. SCOPES = ['https://www.googleapis.com/auth/ediscovery'] def main(): @@ -28,12 +28,11 @@ def main(): Prints the names and IDs of the first 10 matters in Vault. """ creds = None - # The file token.pickle stores the user's access and refresh tokens, and is + # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. - if os.path.exists('token.pickle'): - with open('token.pickle', 'rb') as token: - creds = pickle.load(token) + if os.path.exists('token.json'): + creds = Credentials.from_authorized_user_file('token.json', SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -43,8 +42,8 @@ def main(): 'credentials.json', SCOPES) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open('token.pickle', 'wb') as token: - pickle.dump(creds, token) + with open('token.json', 'w') as token: + token.write(creds.to_json()) service = build('vault', 'v1', credentials=creds)