In the webinterface of Google Drive, cookies are used to remember authification. I would recommend to read the login information from a config file and login each time you use the script. You may use eval()
with that, but remember, eval()
is evil :) (If the script is only used by you, it's okay).
Sample:
Create a file called login.conf
(or similar) in the same folder your script is in. The put this in it:
{"user": "username", "pass": "password"}
Replace "username"
and "pasword"
with your real values, but keep the "
. In your script, do it like this:
with open("login.conf", "r") as f:
content = eval(f.read())
username = content["user"]
password = content["pass"]
# Now do login using these two variables
A more secure option would be the usage of ConfigParser
(configparser
in Python 3.x).
EDIT:
It looks like login to Google Drive requires afile called client_secrets.json
in the directory of your script. If you have it, do login like this:
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
gauth.LoadCredentialsFile("credentials.txt")
if gauth.credentials is None:
gauth.LocalWebserverAuth()
elif gauth.access_token_expired:
gauth.Refresh()
else:
gauth.Authorize()
gauth.SaveCredentialsFile("credentials.txt")
drive = GoogleDrive(gauth)
Hope this helps (Ask, if something is not clear enough)!