0

I have this example where I upload a csv file in my Google Drive, but a browser page is opened, and I don't want it. In addition to this, I created a project in Google Cloud where I enabled Google Drive API, generated a OAuth 2.0 client ID and added the client_screts.json file in my working directory.

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
gauth.LocalWebserverAuth()

drive = GoogleDrive(gauth)

file1 = drive.CreateFile({"mimeType": "text/csv"})
file1.SetContentFile("test.csv")
file1.Upload()
print("finished")

In my new implementation, I tried creating a new project where I did the same, but with a service account. I tried to follow the example here, but with no results: How to connect pydrive with an Service Account

from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from oauth2client.service_account import ServiceAccountCredentials

gauth = GoogleAuth()
scope = ["https://www.googleapis.com/auth/drive"]

gauth.credentials = ServiceAccountCredentials.from_json_keyfile_name("drive2.json", scope)

drive = GoogleDrive(gauth)

file1 = drive.CreateFile({"mimeType": "text/csv"})
file1.SetContentFile("test.csv")
file1.Upload()
print("finished")

The second version does not throw any error, but is not doing what I want either. What should be done here?

Alex B
  • 35
  • 6
  • In your second implementation at this file1 = drive.CreateFile({"mimeType": "text/csv"}) line you have used drive but it is not defined anywhere so you should probably get error. – Smaurya Jun 30 '22 at 15:35
  • Forgot it here, I edited the post, thank you. – Alex B Jun 30 '22 at 15:54
  • If your issue has still not resolved, can I ask you about the detail of `but is not doing what I want either` of `The second version does not throw any error, but is not doing what I want either.`? – Tanaike Jul 01 '22 at 01:11

0 Answers0