Closed phen1 closed 1 year ago
The regular Auth flow doesn't imply / require running gauth.LoadCredentialsFile()
. It's more of an internal, advanced call that expects different credentials.
One way is to have a settings.yaml
, client_secrets.json
that you downloaded from GCP:
client_config_backend: file
client_config_file: client_secrets.json
save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json
get_refresh_token: True
oauth_scope:
- https://www.googleapis.com/auth/drive
- https://www.googleapis.com/auth/drive.file
- https://www.googleapis.com/auth/drive.install
- https://www.googleapis.com/auth/drive.readonly
and use code like this:
import os
from pydrive2.auth import GoogleAuth
from pydrive2.drive import GoogleDrive
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
drive = GoogleDrive(gauth)
Option 2 is to pass settings.yaml
as a dict into GoogleAuth()
. Similar to this example:
settings = {
"client_config_backend": "file",
....
}
# Create instance of GoogleAuth
gauth = GoogleAuth(settings=settings)
# Authenticate
gauth.ServiceAuth()
return gauth
Option 3 is similar to option 2, but you can pass client config also as part of that dict. The full config can be found here - https://docs.iterative.ai/PyDrive2/oauth/
. See the These are all the possible fields of a settings.yaml file:
part.
I got this error when I try to use this Pydrive2
And this is my code: