This is a question I had moments ago.
It was answered in How do you get and use a Refresh Token for the Dropbox API (Python 3.x)
Those answers are all redundant though.
Following the example on: https://github.com/dropbox/dropbox-sdk-python/blob/main/example/oauth/commandline-oauth-pkce.py
You can create a auth-flow object with token_access_type: ‘offline’:
auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, use_pkce=True, token_access_type=’offline’)
After authenticating the usual way using that auth_flow object, you then open a dropbox object using:
with dropbox.Dropbox(oauth2_refresh_token=auth-flow.final(authcode).refresh_token, app_key=APP_KEY) as dbx:
You fetch the results.
oauth_result = auth_flow.finish(auth_code)
And then you create a dropbox object:
with dropbox.Dropbox(oauth2_refresh_token=oauth_result.refresh_token, app_key=APP_KEY) as dbx:
This was typed on a phone, excuse the format.
I wanted to put this as an answer to the question, but I have no reputation.
You can delete this or post this as an answer there if you like, just thought it would help someone.
DutchGreen is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.