cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API Version

API Version

David M.232
New member | Level 1

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?

10 Replies 10

Greg-DB
Dropbox Staff

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.

David M.232
New member | Level 1

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.

David M.232
New member | Level 1

Also to note, another developer is writing the IOS version and his app is working.

Greg-DB
Dropbox Staff

What SDK are you using? Can you share your code? Can you copy any output you are getting?

David M.232
New 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");
            }
        }
    }
}

David M.232
New member | Level 1

Not sure how the paste screen shots here.

Greg-DB
Dropbox Staff

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.

David M.232
New member | Level 1

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.

David M.232
New member | Level 1

Sorry I see in the Developer console were to generate the access token. Does this need to be in the Android code?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    David M.232 New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?