I tried to run the following script, however I get the error, Error authenticating: 'service_config'. I am unable to figure out why it isn't working. Thanks!
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive
# Authenticate using service account credentials
gauth = GoogleAuth()
gauth.service_account_email = 'tiktokuploadacc@tiktikchannel.iam.gserviceaccount.com'
gauth.service_account_file = './service_account.json' # Replace with the correct path to your service account JSON file
gauth.scope = ['https://www.googleapis.com/auth/drive']
gauth.auth_method = 'service'
try:
gauth.ServiceAuth()
except Exception as e:
print("Error authenticating:", e)
exit(1)
# Initialize GoogleDrive instance
drive = GoogleDrive(gauth)
# Example: Create a simple text file and upload it
folder_id = '1BxjyaQ2eRo9CEYdN1CaeBQRIjzCblo57' # Replace with the ID of the folder where you want to upload the file
file_content = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
file_name = "abc.txt"
try:
file = drive.CreateFile({'title': file_name, 'parents': [{'id': folder_id}]})
file.SetContentString(file_content)
file.Upload()
print("File uploaded successfully:", file['title'])
except Exception as e:
print("Error uploading file:", e)
I tried to run the following script, however I get the error,
Error authenticating: 'service_config'
. I am unable to figure out why it isn't working. Thanks!