5

Does anyone have any example or documentation how to connect a Service Account from Google Drive API with pydrive. I managed to do it with auth2 client.

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Luca Vlad
  • 95
  • 1
  • 8
  • Ever figured out how to make this work properly? It seems to work with the method suggested below at first, but then after 1 hour (3600 seconds) the session expires and it fails to renew (for some reason pydrive2 tries to use a different mode, spews "InvalidConfigError" looking for nonexistent file client_secrets.json) – Manchineel Jul 29 '22 at 00:25

1 Answers1

4

Apparently this should work, but it does not:

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(JSON_FILE, scope)
drive = GoogleDrive(gauth)

UPDATE: error was caused by some missing permissions in google IAM.

glasz
  • 2,526
  • 25
  • 24
Luca Vlad
  • 95
  • 1
  • 8
  • 1
    Ever figured out how to make this work properly? It seems to work at first, but then after 1 hour (3600 seconds) the session expires and it fails to renew (for some reason pydrive2 tries to use a different mode, spews "InvalidConfigError" looking for nonexistent file client_secrets.json) – Manchineel Jul 29 '22 at 00:25