python-3.xpydrive

How to connect pydrive with an Service Account


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.


Solution

  • 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.