How do I authenticate to DropboxAPI v2 for Android?
I have just started and I am following this guide
https://www.dropbox.com/developers/documentation/java#tutorial
But no login. Nothing asks you to enter a username, password. This means that I cannot get the GUI that every application has with the "Share to Dropbox" option.
Am I stuck with one account? Should I find a way to get the ACCESS_TOKEN person or is there a more elegant GUI solution out there (with google drive and their intentsenders for example)?
source to share
To use the Dropbox API v2 on Android, you must be using the Java SDK API v2 . There's a sample Android app that uses it in the SDK. You should refer to this as an example of how to implement an application authorization flow that is done through OAuth 2. This requires the user to authorize your application with Dropbox, logging into Dropbox when needed. Your application can then save and reuse the resulting access token for that user, as shown here.
Implementing this way allows anyone to connect their Dropbox account to your app. You can also handle multiple accounts per instance of your application.
source to share
Unfortunately, there is not much documentation on this thread. This is how I was able to successfully authenticate users. First, you want to start the authentication flow using the Dropbox auth action:
import com.dropbox.core.android.Auth
....
Auth.startOAuth2Authentication(context, context.getString(R.string.dbx_api_app_key))
After the user is successfully authenticated, call the following method in the onResume
activity method where you started the Dropbox activity:
@Override
public void onResume() {
super.onResume();
String token = Auth.getOAuth2Token()
}
token
which you get here should be used when you instantiate your instance DbxClientV2
like this:
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder(MyUtils.getVersionText(context))
.withHttpRequestor(OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
.build()
DbxClientV2 dbxClient = DbxClientV2(requestConfig, accessToken)
You will also need the following dependencies in your file build.gradle
:
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp3:okhttp:3.7.0'
source to share