I'm working on a program that uploads files to Google Drive using pydrive.
It works when I'm running it in IDLE but gives me a Google authorization error when running it as an executable (made using auto-py-to-exe). I think it's because the executable can't find the client_secrets.json file. How can I tell the executable where that file is?
from pydrive.drive import GoogleDrive
from pydrive.auth import GoogleAuth
credentials = '/Drive credentials/client_secret_number.apps.googleusercontent.com.json'
folder_id = 'folder_id'
gauth = GoogleAuth()
gauth.LoadCredentialsFile("mycreds.txt")
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() ### THIS IS CAUSING THE ERROR
# Save the current credentials to a file
gauth.SaveCredentialsFile("guts/mycreds.txt")
drive = GoogleDrive(gauth)
file = drive.CreateFile({'parents':[{'id': folder_id}]})
file.SetContentFile('filename.xlsx')
file.Upload()
share_link = file['alternateLink']