From f8da7d3db7b4a0e12efd47a1784ed970e8ec6aed Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Fri, 9 Oct 2020 14:09:23 -0700 Subject: [PATCH] Add automatic refreshing of the Google Sheets token Otherwise, the original token expires and becomes useless after 60 minutes. --- turbot/sheets.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/turbot/sheets.py b/turbot/sheets.py index 7e6ddea..a578b10 100644 --- a/turbot/sheets.py +++ b/turbot/sheets.py @@ -3,6 +3,7 @@ import pickle import os.path import os +from google.auth.transport.requests import Request from googleapiclient.discovery import build TEMPLATE_SHEET_ID = "1drSoyrE4gM3JaGweDkOybwXWdKPIDTfUmB1gQCYS3Uw" @@ -26,6 +27,10 @@ def sheets_create(name): with open(TOKEN_FILE, 'rb') as token: creds = pickle.load(token) + # Refresh credentials if necessary + if creds and not creds.valid: + creds.refresh(Request()) + # If there are no (valid) credentials available, give up if not creds or not creds.valid: current_app.logger.error("No token found in {}".format(TOKEN_FILE)) -- 2.43.0