Pydrive Google Drive Automate Authentication
I have the following piece of code: from pydrive.auth import GoogleAuth gauth = GoogleAuth() gauth.DEFAULT_SETTINGS = {'save_credentials': True,'client_config_backend': 'settings'
Solution 1:
Actually you need to copy the client_secret.json file to my_cred.txt by the following code:
gauth = GoogleAuth()
# Try to load saved client credentials
gauth.LoadCredentialsFile("mycreds.txt")
if gauth.credentials isNone:
# Authenticate if they're not there
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
# Refresh them if expired
gauth.Refresh()
else:
# Initialize the saved creds
gauth.Authorize()
# Save the current credentials to a file
gauth.SaveCredentialsFile("mycreds.txt")
Then use the following code to initialize the drive:
defauthorize_drive():
gauth = GoogleAuth()
gauth.DEFAULT_SETTINGS['client_config_file'] = "client_secret.json"
gauth.LoadCredentialsFile("mycreds.txt")
return GoogleDrive(gauth)
classDriveReport(object):def__init__(self):
self.drive = authorize_drive()
See more of this link: Automating pydrive verification process
Post a Comment for "Pydrive Google Drive Automate Authentication"