0

I connect my android application with drop box using below code. But, I found that it is automatically disconnect after some time. I don't know why it is happen. May be access token expire or anything else. So, how can I maintain connectivity continuously. Please guide me. Thanks in advance.

public void connect() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(application); String accessToken = prefs.getString(Constants.DROPBOX_ACCESS_TOKEN, null); if (accessToken == null) { accessToken = Auth.getOAuth2Token(); if (accessToken != null) { tracker.send(new HitBuilders.EventBuilder() .setCategory(Analytics.Category.DropBox.name()) .setAction(Analytics.Action.Enable.name()) .build()); prefs.edit().putString(Constants.DROPBOX_ACCESS_TOKEN, accessToken).apply(); try { Bundle bundle = new Bundle(); bundle.putString(FirebaseAnalytics.Param.ITEM_CATEGORY, Analytics.Category.DropBox.name()); bundle.putString(FirebaseAnalytics.Param.ITEM_NAME, Analytics.Action.Enable.name()); FirebaseAnalytics.getInstance(application).logEvent(FirebaseAnalytics.Event.VIEW_ITEM, bundle); } catch (Exception e) { e.printStackTrace(); } } else { unlink(); } } String uid = Auth.getUid(); String storedUid = prefs.getString(Constants.DROPBOX_USER_ID, null); if (uid != null) { if (!uid.equals(storedUid)) { prefs.edit().putString(Constants.DROPBOX_USER_ID, uid).apply(); } } } 

1 Answer 1

2

Dropbox is in the process of switching to only issuing short-lived access tokens (and optional refresh tokens) instead of long-lived access tokens. You can find more information on this migration here.

Apps can still get long-term access by requesting "offline" access though, in which case the app receives a "refresh token" that can be used to retrieve new short-lived access tokens as needed, without further manual user intervention. You can find more information in the OAuth Guide and authorization documentation.

For Android apps using the official Dropbox API v2 Java SDK, to do so, you would start the authorization flow using startOAuth2PKCE (instead of startOAuth2Authentication) as shown here, and handle the result as shown here. When you do so, the credential will include both a short-lived access token as well as a refresh token. As long as you pass in those credentials to the client, which includes the refresh token in addition to an access token, the SDK will automatically handle expired short-lived access tokens for you by performing the refresh in the background.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.