def initialize_dropbox_client():
access_token = "my access token"
dbx = dropbox.Dropbox(access_token)
dbx._oauth2_access_token_expiration = time.time() + 14400 # Assume token expires in 1 hour for initial setup
return dbx
# Refresh access token if it's expired
def refresh_access_token():
global dbx # Ensure dbx is accessed as a global variable
client_id = "app id"
client_secret = "app secret"
refresh_token = "resfresh token"
while True:
try:
current_time = time.time()
expiration_time = dbx._oauth2_access_token_expiration
if expiration_time is not None and expiration_time - current_time < 60: # If token expires in less than a minute
data = {
"refresh_token": refresh_token,
"grant_type": "refresh_token",
"client_id": client_id,
"client_secret": client_secret,
}
response = requests.post(token_url, data=data)
new_tokens = response.json()
new_access_token = new_tokens["access_token"]
dbx = dropbox.Dropbox(new_access_token)
dbx._oauth2_access_token_expiration = current_time + new_tokens["expires_in"]
else:
time.sleep(60) # Check again after 1 minute
except dropbox.exceptions.AuthError:
st.error("Authentication error. Please check your access token.")
break
i buid auto refreshing of the access token. but it is not automatically refreshing to the new access token and instead of that it is showing an auth error