from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from typing import * gauth = GoogleAuth() drive = GoogleDrive() gauth.LoadCredentialsFile("client_secrets.json") if gauth.credentials is None: # Authenticate if they're not there gauth.LocalWebserverAuth() elif gauth.access_token_expired: # Refresh them if expired gauth.Refresh() else: # Initialize the saved creds gauth.Authorize() # Save the current credentials to a file gauth.SaveCredentialsFile("client_secrets.json") def upload_gdrive(upload_file_list:list[str]): for upload_file in upload_file_list: gfile = drive.CreateFile({'parents': [{'id': '1pzschX3uMbxU0lB5WZ6IlEEeAUE8MZ-t'}]}) # Read file and set it as the content of this instance. gfile.SetContentFile(upload_file) gfile.Upload() # Upload the file.