Ad

Dropbox Api - Token Expired ( Fastest Way To Refresh )

- 1 answer

I've generated the access token manually over the Dropbox App Console on their webpage. Developer Apps

With that token I was able to download the file

mydropbox_token = 'sl.....' 
dbx = dropbox.Dropbox(mydropbox_token,app_key='vixxx',app_secret='qrxxx') 
with open("rc.xlsx", "wb") as f:
    shared_link = "https://www.dropbox.com/s/e9xxxxxxx.xlsx?dl=0"
    metadata, res = dbx.sharing_get_shared_link_file(url=shared_link,link_password
='xxx1')
    f.write(res.content)

The point here is I just want to be able to download this public shared , password protected file and to do so I must have dropbox access key, which I don't know why.

My question is, what is fastest way to automatically generate, refresh tokens through code instead of manually copy/pasting them every few days.

Ad

Answer

To retrieve a refresh token, you'll need to use the OAuth app authorization flow.

It is not possible to fully automate the OAuth process where the user chooses to authorize the app and the app then receives the resulting access token and optional refresh token. This needs to be done manually by the user at least once. If your app needs to maintain long-term access without the user manually re-authorizing it repeatedly, the app should request "offline" access so that it gets a refresh token. The refresh token doesn't expire and can be stored and used repeatedly to get new short-lived access tokens whenever needed, without the user manually reauthorizing the app.

You can find examples of using the OAuth app authorization flow in the Dropbox Python SDK here.

Ad
source: stackoverflow.com
Ad