cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Share your feedback on the Document Scanning Experience in the Dropbox App right here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: Acces token for python django

Acces token for python django

dmartinez
Explorer | Level 3

Hello, im trying to acces with a django porject to my own account files but the short live tokens renew each 4 hours i tried generating the offline token but it results on renewing it again, i am not that into oauth so im having issues on this part oculd someone helpme trying to get arround this issue, again is for my own account im using the list folder for downloading some fileds and working with panda but i want a permanent token for not having some to give permision to acces dropbox.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff

@dmartinez Здравко is correct; for long-term access you should use a refresh token. Refresh tokens do not expire and can be used repeatedly. You do not need to re-authorize the app each time. Once you have a refresh token you can store and re-use that refresh token without further manual action.

 

The official Dropbox Python SDK will handle the details of how to use a refresh token for you, so you would just need to make the Dropbox client object like this, if you used PKCE to retrieve the refresh token:

dropbox.Dropbox(oauth2_refresh_token=REFRESH_TOKEN, app_key=APP_KEY)

or like this, if you did not use PKCE to retrieve the refresh token:

dropbox.Dropbox(oauth2_refresh_token=REFRESH_TOKEN, app_key=APP_KEY, app_secret=APP_SECRET)

 

For reference, you can find more information on how this works at the following resources:

View solution in original post

3 Replies 3

Здравко
Legendary | Level 20

Hi @dmartinez,

For long term access you need refresh token. If a supported SDK is in use just proper initialization is enough (for the rest SDK takes care), otherwise tracing access token validity and refresh whenever needed should be performed. So you wouldn't need "to give permision to acces dropbox" (no repeatedly at least - only once at the beginning). :winking_face:

Hope this gives direction.

Greg-DB
Dropbox Staff

@dmartinez Здравко is correct; for long-term access you should use a refresh token. Refresh tokens do not expire and can be used repeatedly. You do not need to re-authorize the app each time. Once you have a refresh token you can store and re-use that refresh token without further manual action.

 

The official Dropbox Python SDK will handle the details of how to use a refresh token for you, so you would just need to make the Dropbox client object like this, if you used PKCE to retrieve the refresh token:

dropbox.Dropbox(oauth2_refresh_token=REFRESH_TOKEN, app_key=APP_KEY)

or like this, if you did not use PKCE to retrieve the refresh token:

dropbox.Dropbox(oauth2_refresh_token=REFRESH_TOKEN, app_key=APP_KEY, app_secret=APP_SECRET)

 

For reference, you can find more information on how this works at the following resources:

dmartinez
Explorer | Level 3

 thank you, i was testing this approach this days i delivered the app and just gave it the autorization and still working, thank you for the help !

Need more support?