Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't upload file with my service account #348

Closed
P3eky opened this issue May 22, 2024 · 1 comment
Closed

Can't upload file with my service account #348

P3eky opened this issue May 22, 2024 · 1 comment

Comments

@P3eky
Copy link

P3eky commented May 22, 2024

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)
@P3eky
Copy link
Author

P3eky commented May 23, 2024

I found a different method I do not need a response.

@shcheklein shcheklein closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants