You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
morkus
3 years agoHelpful | Level 5
How to automate getting a new token using Java?
Now that DB uses "short-lived" tokens, I am having trouble "automating" token refresh within an application.
Using the Java code examples, I can get the DB URL where I manually have to log into the DB site, get the new access code, and, again, manually, copy that back to the application (
.ShortLiveTokenAuthorize().authorize(appInfo);
So, my question is ... is there a way to get the new access token programmatically with NO manual steps? So, when the user goes to "upload" (in my case), it ... ALWAYS works;
Using OAUTH in other apps I can automated refreshing the token, but I haven't seen an example how to do it with DB.
Thanks in advance!
Yes, that's correct. The SDK client knows how to use the credentials (refresh token, app key, and for the non-PKCE case, app secret) to automatically perform the refresh process whenever needed, so that calls continue to work.
- Greg-DBDropbox Staff
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.
Here's some example code of processing the authorization flow using the official Dropbox API v2 Java SDK, such as to get a refresh token:
For instance, here's a line where it requests "offline" access in order to get a refresh token:
And here's an example of storing the refresh token:
As long as you supply the necessary credentials, the SDK will then handle the refresh process for you automatically, e.g.:
- morkusHelpful | Level 5
Thank you!
- morkusHelpful | Level 5
I used the top Java program you listed to do the manual approach.
If I understood your reply correctly (a show-stopper), I'm disappointed that there's no total programmatic way to get a new token when expired. We can't expect our users to go to the DB website click here and there, get a new access key, and paste it into the client-side application.
Thanks
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,882 PostsLatest Activity: 6 minutes agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!