Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
We have a mobile app accessing Dopbox. We have cloned the app and customized it from another customer. I can use the old keys and can access Dropbox with new app. If I use the new keys created for the new app, I can't access it. Is there a new API that we need to change that wasn't required before?
What exactly do you mean when you say "can't access it"? What error are you getting?
One thing to note is that access tokens are app-specific, so you can't use an access token from the original app with the new app key and secret. If that is what you're trying to do, you'll need to process the app authorization flow again, this time using the new app key and secret, in order to get an access token for the new app.
I don't see anything. No error. If I looking at the developer console. I don't see any developer access count. Just strange that all I am doing is changing the key values.
Also to note, another developer is writing the IOS version and his app is working.
What SDK are you using? Can you share your code? Can you copy any output you are getting?
//Dropbox variables
final static private String DROPBOX_APP_KEY = "Key Here";
final static private String DROPBOX_APP_SECRET = "App Secret Here";
final static private AccessType DROPBOX_ACCESS_TYPE = AccessType.DROPBOX;
public DropboxAPI<AndroidAuthSession> mDBApi;
private void initializeDropbox() {
AppKeyPair appKeys = new AppKeyPair(DROPBOX_APP_KEY, DROPBOX_APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, DROPBOX_ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
//Create DropboxUtil class that will be used in this app's Javascript
DropboxUtils dropboxUtils = new DropboxUtils(this, appView);
appView.addJavascriptInterface(dropboxUtils, "DropboxUtils");
///////
}
import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.session.AccessTokenPair;
import com.dropbox.client2.session.AppKeyPair;
import com.dropbox.client2.session.Session.AccessType;
public boolean isDropBoxAuthenticated() {
String key = mPrefs.getString("dropboxAuthKey", null);
String secret = mPrefs.getString("dropboxAuthSecret", null);
if (key != null && secret != null) {
if (mDBApi.getSession().isLinked())
return true;
else {
AccessTokenPair access = new AccessTokenPair(key, secret);
mDBApi.getSession().setAccessTokenPair(access);
}
if (mDBApi.getSession().isLinked())
return true;
else
return false;
}
return false;
}
public void dropBoxAuthenticate(String queryParams) {
SharedPreferences.Editor ed = mPrefs.edit();
ed.putString("queryParams", queryParams);
ed.putBoolean("dbAuthenticating", true);
ed.commit();
//Log.i(LOG_TAG, "**queryParams " + queryParams);
mDBApi.getSession().startAuthentication(App.this);
}
protected void onResume() {
super.onResume();
boolean dbAuthenticating = mPrefs.getBoolean("dbAuthenticating", false);
if (mDBApi.getSession().authenticationSuccessful() && dbAuthenticating) {
try {
// MANDATORY call to complete auth.
// Sets the access token on the session
mDBApi.getSession().finishAuthentication();
AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();
// Provide your own storeKeys to persist the access token pair
// A typical way to store tokens is using SharedPreferences
SharedPreferences.Editor ed = mPrefs.edit();
ed.putString("dropboxAuthKey", tokens.key);
ed.putString("dropboxAuthSecret", tokens.secret);
String queryParams = mPrefs.getString("queryParams", null);
ed.remove("queryParams");
ed.remove("dbAuthenticating");
ed.commit();
super.loadUrl("file:///android_asset/www/dropboxFileBrowser.html" + (queryParams == null ? " : queryParams));
} catch (IllegalStateException e) {
//Log.i(LOG_TAG, e.getMessage());
}
} else {
if (mPrefs.getBoolean("appInit", true) == true) {
//This condition occurs because of displaying the splash screen
SharedPreferences.Editor ed = mPrefs.edit();
ed.putBoolean("appInit", false);
ed.commit();
} else {
String queryParams = mPrefs.getString("queryParams", " ");
if (queryParams.indexOf("editProfile") != -1) {
//This condition occurs if the user cancels dropbox authentication
//and facebook authentication
SharedPreferences.Editor ed = mPrefs.edit();
ed.remove("queryParams");
ed.commit();
super.loadUrl("file:///android_asset/www/profile.html?editProfile=1");
}
else if (nativeAppLoggedIn()) {
//Log.i(LOG_TAG, "**Going to index");
super.loadUrl("file:///android_asset/www/index.html");
}
else {
//Log.i(LOG_TAG, "**Going to login");
//super.loadUrl("file:///android_asset/www/login.html");
}
}
}
}
Not sure how the paste screen shots here.
Thanks, that's helpful. Ok, so it looks like you're using the Android Core SDK. That presumably means you're using either Eclipse or Android Studio. In either case, when you use mDBApi
to make an actual API call after all of the setup you have here, if something went wrong it would raise an exception with specific information about the issue.
I don't see where you make an API call using mDBApi
in the provided code (presumably you do that later?), but I do see what I suspect is the issue. Specifically:
String key = mPrefs.getString("dropboxAuthKey", null);
String secret = mPrefs.getString("dropboxAuthSecret", null);
...
AccessTokenPair access = new AccessTokenPair(key, secret);
mDBApi.getSession().setAccessTokenPair(access);
It looks like you're retrieving a pre-existing access token, presumably for the old app. Since access tokens (the dropboxAuthKey
and dropboxAuthSecret
pair in your code) are specific to apps, you'll need to get a new access token for the new app key/secret.
If that doesn't seem to be the problem, e.g., if the code isn't going through that code path, please copy the relevant output you get when you run this. E.g., from logcat.
The code is here. Just a little different from your example
private void initializeDropbox() {
AppKeyPair appKeys = new AppKeyPair(DROPBOX_APP_KEY, DROPBOX_APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, DROPBOX_ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
//Create DropboxUtil class that will be used in this app's Javascript
DropboxUtils dropboxUtils = new DropboxUtils(this, appView);
appView.addJavascriptInterface(dropboxUtils, "DropboxUtils");
I understand about the new key pairs. Yes we have a separate key pair for each app. Just to check the code, I added the old key to the new code. I am assume that there isn't other parameter that would change between key pairs. If the code works with one set of keys, shouldn't it work with the other set. I didn't know if new app required a different api level from the time we create the other app. Nothing has changed in the code, but the keys.
Sorry I see in the Developer console were to generate the access token. Does this need to be in the Android code?
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!