I have the following piece of code:
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.DEFAULT_SETTINGS = {\'save_credentials\': True,\'client_c
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 is None:
# 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:
def authorize_drive():
gauth = GoogleAuth()
gauth.DEFAULT_SETTINGS['client_config_file'] = "client_secret.json"
gauth.LoadCredentialsFile("mycreds.txt")
return GoogleDrive(gauth)
class DriveReport(object):
def __init__(self):
self.drive = authorize_drive()
See more of this link: Automating pydrive verification process