Reputation: 393
Is it possible to use both the Core and Sync Api in one Android app?
Upvotes: 0
Views: 55
Reputation: 393
It is possible to use them together. It's a 2 part setup.
Removing Project errors:
client2.Auth
classes - anything that's causing a namespace collision. You will see errors until this is fixedAuthenticating the SDKs:
Get the oAuth credentials from Sync SDK for your Core SDK using:
AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeyPair);
session.setOAuth2AccessToken(getTokenFromSyncAPI());
session.finishAuthentication();
And finally, the missing method:
String getTokenFromSyncAPI() {
String token = null;
String allTokens = getApplicationContext().getSharedPreferences("dropbox-credentials",
Context.MODE_PRIVATE).getString("accounts", null);
try {
JSONArray jsonAccounts = new JSONArray(allTokens);
if (jsonAccounts.length() > 0) {
String tmpToken = null;
tmpToken = jsonAccounts.getJSONObject(0).getString("userToken");
// We take only oAuth2 tokens
if (tmpToken.startsWith("|oa2|"))
token = tmpToken.substring(5);
}
} catch (JSONException e) {
e.printStackTrace();
}
return token;
}
Method courtesy : https://blogs.dropbox.com/developers/2015/05/migrating-sync-sdk-access-tokens-to-core-sdk/
PS : The method shown at the link has a bug. substring(6)
instead of 5
Upvotes: 1