4

I have successfully used this client_secret.json to authenticate with Google API and read gSheet data, but now I am trying to upload a file to Drive using pydrive.

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

gauth = GoogleAuth()
gauth.LoadClientConfigFile('client_secret.json') # fails here
drive = GoogleDrive(gauth)
gfile = drive.CreateFile()
gfile.SetContentFile('myfile.txt')
gfile.Upload()

Error: InvalidConfigError('Invalid client secrets file %s' % error) pydrive.settings.InvalidConfigError: Invalid client secrets file Invalid file format See https://developers.google.com/api-client-library/python/guide/aaa_client_secrets Expected a JSON object with a single property for a "web" or "installed" application

Joe
  • 3,217
  • 3
  • 21
  • 37

1 Answers1

0

Your current json file cannot be used, as the error states that it didn't find the properties web or installed on the json structure. Make sure that you are creating a OAuth client ID and selecting "Desktop app" as Application type when you are creating your credentials. After creating the credential, you will be able to download a json file and it will have the property installed if you generate the way I described above.

If you create a Service Account credential, you will be able to generate a json file too, but it won't have the necessary property in the json. Check the documentation on how to generate the credentials: https://developers.google.com/drive/api/quickstart/python

Eduardo Matsuoka
  • 566
  • 6
  • 18