0

I'm developing an android app, just for myself really, to learn android and also to make something useful for myself. The app is sort of an extension to a desktop application that I wrote. One of the things that the desktop app does is upload some textual data and images to a Dropbox account that I created just for this purpose.

The android app offers a pared down implementation of the desktop app, so that I can get some of the same functionality on-the-go. So, when the android app starts up, it checks the dropbox account and downloads any new data that it doesn't already have.

For the desktop app (Python), I just did an authentication manually by hitting the dropbox auth endpoint with my dropbox app key (in a browser) and then using the 'code' I got from that to finally get an access token. So I've hardcoded that token into my desktop app, and it bypasses the oAuth process and just uses the token for authentication. It's uploading data just fine.

But whereas the Python Dropbox API allows me to do that, I'm not sure how to do that with the android dropbox API. I've been browsing through the classes in the JavaDocs for the API, but it seems that I have to go through the oAuth process to get an AccessTokenPair for authentication (which seems to consist of a key and a secret). Can I not just provide the same token I use in the desktop app to some object (a DropboxAPI instance, maybe) to get authenticated?

I realize now that this kind of use for Dropbox is probably not very intuitive, but I'm invested now so I'd like to make it work if I can.

EDIT:
It seems that you can avoid having to go through the oAuth process if you have an AccessTokenPair (or it's values) saved from a previous authentication session. It looks like the AccessTokenPair is just wrapper for two strings: key and secret. So I suppose my question is now, what are these two values. I have an access token, which is a ~64 character string that my desktop app is using successfully for authentication. Can I use this to create an AccessTokenPair object, and if I can, is it a key or a secret and what I'm I missing?

SOLUTION:
As Smarx has said, the problem is that the Android and iOS Dropbox clients use oAuth1 whereas the Python, Ruby, PHP and Java clients use oAuth2. So, I actually ended up just following the oAuth1 process for Android, logging the resulting access key and secret and then hardcoding those for future use to bypass the oAuth process. It seems to be working fine.

2

2 Answers 2

1

Are you using the Core API or Sync API?

In the case of the Sync API, I think there's no easy way to use a token you already have.

In the case of the Core API, I think you can do it, but I believe the Android Core SDK still uses OAuth 1, and my guess is that you have an OAuth 2 token.

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

1 Comment

It's the Core API, and yes, that does seem to be the problem. I've updated my question. I wonder though, is there any disadvantage to just using the Java client in an Android app, as opposed to the Android client?
0

the oauth1 API seems to be deprecated. Looks like this is certainly a deficiency, because I am trying the same thing and it is completely broken basically, I can authenticate and then generate an oauth2 token which is stored but using it I couldn't logon again, unless I rebuild the API object again.

EDIT: sorry about the multiple comments below, I do not seem to have the privilege of being able to delete my own comments.

EDIT: yay now I can delete my own comments so answer is below:

//first logon - get the token and save it to shared prefs

if (emboDBApi.getSession().authenticationSuccessful()) { 
    try { 
        emboDBApi.getSession().finishAuthentication(); 
        String accessToken = emboDBApi.getSession().getOAuth2AccessToken();
        SharedPreferences.Editor editor = prefs.edit();   
        editor.putString("emboDBAccessToken", accessToken); editor.apply();     
        } 
    catch (IllegalStateException e) { Log.v(TAG, "Error authenticating", e);
} 

}

//for subsequent logons use the saved token if it exists and then create a    
auth session from that.

AndroidAuthSession newSession = new AndroidAuthSession(Constants.KEY_PAIR,     
prefs.getString("emboDBAccessToken", "")); 
emboDBApi = new DropboxAPI<AndroidAuthSession>(newSession);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.