Signed-off-by: Jeroen Oudshoorn <oudshoorn.jeroen@gmail.com>
This commit is contained in:
Jeroen Oudshoorn
2023-10-13 09:22:13 +02:00
parent 0ac2524d3e
commit 23adb50f3a

View File

@ -71,6 +71,23 @@ def refresh():
try: try:
# Try to load saved client credentials # Try to load saved client credentials
gauth.LoadCredentialsFile("/root/credentials.json") gauth.LoadCredentialsFile("/root/credentials.json")
if gauth.access_token_expired:
if gauth.credentials is not None:
try:
# Refresh the token
gauth.Refresh()
except pydrive2.auth.RefreshError:
print(gauth.GetAuthUrl())
user_input = input("Please copy this URL into a browser, "
"complete the verification and then copy/paste the code from addressbar.\n\n"
"Code: ")
gauth.Auth(user_input)
else:
print(gauth.GetAuthUrl())
user_input = input("Please copy this URL into a browser, "
"complete the verification and then copy/paste the code from addressbar.\n\n"
"Code: ")
gauth.Auth(user_input)
except pydrive2.auth.InvalidCredentialsError: except pydrive2.auth.InvalidCredentialsError:
print(gauth.GetAuthUrl()) print(gauth.GetAuthUrl())
user_input = input("Please copy this URL into a browser, " user_input = input("Please copy this URL into a browser, "
@ -78,23 +95,6 @@ def refresh():
"Code: ") "Code: ")
gauth.Auth(user_input) gauth.Auth(user_input)
if gauth.access_token_expired:
if gauth.credentials is not None:
try:
# Refresh the token
gauth.Refresh()
except pydrive2.auth.RefreshError:
print(gauth.GetAuthUrl())
user_input = input("Please copy this URL into a browser, "
"complete the verification and then copy/paste the code from addressbar.\n\n"
"Code: ")
gauth.Auth(user_input)
else:
print(gauth.GetAuthUrl())
user_input = input("Please copy this URL into a browser, "
"complete the verification and then copy/paste the code from addressbar.\n\n"
"Code: ")
gauth.Auth(user_input)
gauth.Authorize() gauth.Authorize()
print("No refresh is required.") print("No refresh is required.")
return 0 return 0