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’:
DropboxOAuth2FlowNoRedirect(APP_KEY, use_pkce=True, token_access_type=’offline’) which will return a refresh token.
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:
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.