Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
David M.232
10 years agoNew member | Level 1
API Version
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...
David M.232
10 years agoNew member | Level 1
//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");
}
}
}
}
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!