cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 

Android authentication

alca
Explorer | Level 3

In the previous api login could be performed to the device dropbox account by using the api key and the api secret, is there any way to do this with V2? What a I need is to be able to connect to diferent dropbox accounts in  V2?

12 Replies 12

Re: Android authentication

alca
Explorer | Level 3

There was a mistake with the post dont know ho to edit so I follow after "accounts in" before V2.

 

diferent devices, if this is not possible any more, what would be the best way to implement it on V2?

Re: Android authentication

Dropboxer
Dropboxer

The app key and secret themselves are not enough to connect to a Dropbox account, in either API v1 or API v2. 

 

To connect to a Dropbox account via the API, you need an "access token". You can get an access token for the user by sending the user through the OAuth app authorization flow. You can find an example implementation of doing this on Android with the API v2 Java SDK here:

 

https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android

 

Specifically, the process is initiated here:

 

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/c...

 

And completed here:

 

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/android/src/main/java/com/dropbox/c...

 

One difference between API v1 and API v2 is that API v2 uses OAuth 2 exclusively, where the app secret is not necessary for client-side apps, such as on Android. Only the app key is needed to start the OAuth app authorization flow and get an access token for the current user.

Re: Android authentication

alca
Explorer | Level 3

Im not sure if I´m doing this OK, but this is what I do and application crushes:

 

Auth.startOAuth2Authentication(this, this.RASVIET_APP_KEY_V2);
String accessToken = Auth.getOAuth2Token();

 

this is an activitie that

extends PreferenceActivity

 and rasviet_app_key_v2 is my key for the app

Re: Android authentication

Dropboxer
Dropboxer
Are you calling startOAuth2Authentication and getOAuth2Token together like that? You should use just startOAuth2Authentication to initiate the app authorization flow. You should then later call getOAuth2Token to complete the app authorization flow in onResume. (Please refer to the samples linked in my previous post.)

Otherwise, please share the full error/output you're getting.

Re: Android authentication

alca
Explorer | Level 3

I am using 3.0.3 dropbox core sdk and it doesnt find v7 in android.support.v7.app.AppCompatActivity

Re: Android authentication

Dropboxer
Dropboxer
Can you share the steps and code to reproduce the issue? Thanks in advance!

Re: Android authentication

alca
Explorer | Level 3

In build.grade file I add this:

dependencies {

compile files('libs/dropbox-core-sdk-3.0.3.jar')
}

 and add the jar with that name under the libs folder, then I create a new class just as the example with this code:

package com.rasviet.mobility.sincro;

import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;

import com.dropbox.core.android.Auth;

/**
* Created by Jritxal on 01/08/2017.
*/

public class DropboxActivity extends AppCompatActivity {
}

 and it says it cannont resolve v7 that apears in red and so does AppCompatActivity ofc.

Re: Android authentication

Dropboxer
Dropboxer
It sounds like you're having trouble importing the Android support library, as opposed to Dropbox itself. I can't offer much help with that, but there's a post about it here:

https://stackoverflow.com/questions/30803405/cannot-resolve-symbol-appcompatactivity-support-v7-libr...

By the way, it looks like you're loading the Dropbox library from the jar file, but since you're using gradle anyway, we recommend just using the setup as documented here:

https://github.com/dropbox/dropbox-sdk-java#setup

Re: Android authentication

jritxalç
Explorer | Level 3

Hello, finally I made it work!!

 

My prob now is that I suppose I need the

DbxClientV2 client;

 variable to keep making calls to the api, I have declared it as public static on my main class (SyncActivity) and do this on the DropboxConnection class:

protected void loadData() {
new GetCurrentAccountTask(DropboxClientFactory.getClient(), new GetCurrentAccountTask.Callback() {
@Override
public void onComplete(FullAccount result) {
SyncActivity.client = DropboxClientFactory.getClient();
finish();
}

@Override
public void onError(Exception e) {
Toast.makeText(getApplicationContext(), "Failed to get account details.",
Toast.LENGTH_LONG).show();
}
}).execute();
}

 but I´m trying to use it on the onResume method of SyncActivity class to just get email addres of the user like this:

try {
if (client != null) {
FullAccount account = client.users().getCurrentAccount();
Toast.makeText(SyncActivity.this, "cliente: " + account.getEmail()+ " acc: "+account.toString(),
Toast.LENGTH_LONG).show();

}
}
catch(Exception e)
{
Toast.makeText(SyncActivity.this, "Excepcion: "+e.getMessage(),
Toast.LENGTH_LONG).show();
}

 and Im getting an exception with message: "null"

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?