Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
YanivB
3 years agoHelpful | Level 6
Android app and DropBox API
Hi All,
I need help with Dropbox API and my android (Java) app.
The Idea of the app is to upload images taken from camera in my app to my own dropbox account.
I did as written, pressed the "Generated access token" button in the dropbox consul and all worked.
The problem is after few hours it expires and i get error :
W/System.err: java.lang.RuntimeException: com.dropbox.core.InvalidAccessTokenException: {"error":{".tag":"expired_access_token"},"error_summary":"expired_access_token/"}
1. if I want the app use only my own account , why is it keep expiring ?
2. Then I kept reading/investigating and I add OAuth2Authentication.
it worked well, I got the dropbox web page with permission request by user (me as its my account i try to connect to app).
I got token and I could upload the images to my account.
But again, even I saved that token in app disk for later use, after a day when I try to upload new images and I use the save token from disk, It gives me error that my token expires ....
There isn't any logic to pop the dropbox permission request page each time I want to upload images .....
This is how my code looks like (for num 2 above):
I add in my manifest :
And in code:
You can see in RED my comments to all code.
And this is the linkToDropBoxAccount() method:
Please help.
9 Replies
- Здравко3 years agoLegendary | Level 20
Hi YanivB,
You have probably read some old tutorials and you miss that long lived access token had deprecated and generation of new long lived access token dropped some time ago. That's why your access is limited in time - something normal since relying on access token only. You can still achieve long term access, but you need to handle refresh token instead. Unfortunately there is no a button to generate refresh token (as there is for access token) so you will need to perform OAuth flow least once. Since the only target is your own account you can either perform OAuth flow inside application or by hand and save generated refresh token together with appkey/appsecret (need for refresh process) into the application. To keep your account safe, you shouldn't share your application to somebody else with embedded pregenerate token of any kind.
Hope this helps.
- YanivB3 years agoHelpful | Level 6
Thanks the answer!
So I already did one time the "OAuth flow" from app code.
So I can get all this:
Now How can I set in code to make it work ? - Здравко3 years agoLegendary | Level 20
Hi again YanivB,
Once you have credentials received somehow you can just use them. You can take a look on one example shown here. It can lead you through the general steps that can work everywhere. You can optimize the way of usage as shown on android example. Otherwise you can construct DbxCredential object and use it to build new client object. 😉
Hope this clarifies matter.
- Greg-DB3 years ago
Dropbox Community Moderator
YanivB Здравко is correct; even for your own account, you will need to get a refresh token to maintain long-term access. Check out the Android example they mentioned, and in particular use the startOAuth2PKCE method to start the authorization flow.
- YanivB3 years agoHelpful | Level 6
Thanks.
are there Java examples for this (not Kotlin....) - Здравко3 years agoLegendary | Level 20
DbxClientV2 client = new DbxClientV2(config, new DbxCredential("", 0, refreshToken, appKey, appSecret)) - YanivB3 years agoHelpful | Level 6
Thanks!
Checking (: - YanivB3 years agoHelpful | Level 6
Another question please.
Is there a way I can listen (callback) when the client finished uploading the files to the account: - YanivB3 years agoHelpful | Level 6
I figured it out, thanks.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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, Facebook or Instagram.
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!