Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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 need to authenticate every time. Your tutorial says:
"
The finishAuthentication()
method will bind the user's access token to the session. You'll now be able to retrieve it via mDBApi.getSession().getOAuth2AccessToken()
.
You'll need this token again after your app closes, so it's important to save it for future access (though it's not shown here). If you don't, the user will have to re-authenticate every time they use your app. A common way to implement storing keys is through Android's SharedPreferences API.
"
Now I have that accesstoken but how I can authenticate using it? I tried mDBApi.getSession().setOAuth2AccessToken(accessToken)
but then putFile gives a DropboxUnlinkedException
.
It seems to be working now in the way that I wanted. All I did was I moved
session.setOAuth2AccessToken(accessToken);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
Glad to hear you got it working!
I accidentally sent the answer before I had written it fully.
So I did setOAuth2AccessToken()
to session instead of mDBApi.getSession()
.
In other words I changed the order in which I used setOAuth2AccessToken
and mDBApi= new DropboxAPI...
I don't know what was the error and now I'm not even sure if there was error
Actually I am also working on a similar kind of app and facing the same error as you did tuomo s. So kindly help me.. solving it.As the solution you provided is not working in my case..
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
}
I Know it's a little old but do you know how to create a similar method for the java core API? Ive been trying to use different methods to store the accessToken with no success...Any help or recommendation on what you guys did for you App would be appreciated, thank you!
Hi there!
If you need more help you can view your support options (expected response time for a 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!