We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.
Forum Discussion
tuomo s.
10 years agoNew member | Level 1
How to use access token in Dropbox authentication in Android app
Hello. I'm trying to make an Android application that uses Dropbox. I managed to upload some files to Dropbox so that is working. But I would like to store the access token so that the user doesn't n...
tuomo s.
9 years agoNew member | Level 1
So after you have authenticated (written your username and password) you run for example something like this in onResume that saves your accessToken to your preferences.
protected void onResume() {
super.onResume();
String accessToken="DEFAULT";
if (mDBApi.getSession().authenticationSuccessful()
&& !mDBApi.getSession().isLinked()) {
mDBApi.getSession().finishAuthentication();
accessToken = mDBApi.getSession()
.getOAuth2AccessToken();
SharedPreferences settings = getSharedPreferences("my_settings", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("dropboxtoken", accessToken);
editor.commit();
}
}
Next time you start your app you run something like this:
SharedPreferences settings = getSharedPreferences("my_settings", 0);
accessToken = settings.getString("dropboxtoken", "DEFAULT");
if(!accessToken.equals("DEFAULT")){
MyService.mDBApi.getSession().setOAuth2AccessToken(accessToken);
}
else {
// accesstoken was not stored so start authentication
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 2 months 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!