Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- This file contains the authentication required to manipulate Nasser's google sheets via python
- """
- 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
- import gspread
- from oauth2client.service_account import ServiceAccountCredentials
- import sys
- GOOGLE_SHEET_API_SCOPE = ['https://www.googleapis.com/auth/spreadsheets']
- def sheetAuth():
- """This function is used to authenticate and return the creds
- """
- creds = None
- if os.path.exists('token.pickle'):
- with open('token.pickle', 'rb') as token:
- creds = pickle.load(token)
- if not creds or not creds.valid:
- if creds and creds.expired and creds.refresh_token:
- print("The token file is expired, please delete it")
- creds.refresh(Request())
- else:
- flow = InstalledAppFlow.from_client_secrets_file('credentials.json', GOOGLE_SHEET_API_SCOPE)
- creds = flow.run_local_server(port = 8000)
- with open('token.pickle', 'wb') as token:
- pickle.dump(creds, token)
- return creds
Add Comment
Please, Sign In to add comment