cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

v2 API

v2 API

Andre_LB
Explorer | Level 3

Hi Dropbox Team,

I am trying, using Dropbox API, to access my files in Dropbox.
I have already done it with Dropbox API v1 and now I would like to do it with v2.
For this reason, I performed as following:-

1) As suggested, I downloaded the new DropBox-SDK from here:-
https://github.com/dropbox/dropbox-sdk-java

2) I run the file:
..\DropboxApiV2\dropbox-sdk-java-master\gradlew.bat

3) I executed "Import Project" in the Android Studio, and selected the folder:
..\dropbox-sdk-java-master\examples\android

4) I added the following line in the build.gradle file in "dependencies" section:-
compile 'com.dropbox.core:dropbox-core-sdk:3.0.6'

5) But I have the following error:-
Unable to load class 'org.grangle.loading.StyledTextOutput'

Alsothe following lines are marked in red:-
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'

6) I have not yet updated "YOUR_APP_KEY_HERE" in AndroidManifest.xml with my app_key. For obtaining the app_key, in Dropbox Console, when I create the app_key
which name I have to give? Maybe "UserActivity"?

I need your help!
Thank you very much, in advance.
Andre

23 Replies 23

Greg-DB
Dropbox Staff

If you're just trying to run the Android example app as is, you don't need to run gradlew.bat. You can just switch the Dropbox dependency to "compile 'com.dropbox.core:dropbox-core-sdk:3.0.6'" as you mentioned. (You should use that instead of the existing "compile group: 'com.dropbox.core', name: 'dropbox-core-sdk', version: '0-SNAPSHOT', changing: true".)

 

Anyway, I don't see a reference to "org.grangle.loading.StyledTextOutput" in the Android example app. Is that the exact output you're getting? 

 

The com.android.support dependencies are referencing the Android support library. That should already be available, but refer to the Android documentation there if not.

 

Finally, when registering your API app on the Dropbox App Console, you should supply the name of your app that should be presented to your users, e.g., what they would see on the Google Play Store (not "UserActivity").

 

Andre_LB
Explorer | Level 3

Hi Greg,
thanks for your very prompt reply.


Yes, when in Android Studio I execute "Sync Project with Gradle Files", I have this "Gradle Sync Issue":-
      Unable to load class 'org.grangle.loading.StyledTextOutput'
      Possible causes for this unexpected error include:
      * Gradle's dependency cache may be corrupt (this sometimes occur after a network connection timeout)
      * The state of a Gradle build process (daemon) may be corrupt.
         Stopping all Gradle daemons may solve this  problem.
      * Your project may be using a third-part plugin which is not compatible

         with the other plugins in the project or the version of Gradle requested by the project.

 


But for being honest, this is not the only issue.
I mean, in the old Dropbox example (DBRoulette) it was clear its pourpose.
There was a download example and an upload one.
Also, working these two examples, it has been easy to use them.

Now, it is not clear for me what I have to use for authentication, for downloading and for uploading.
It is not clear for me, which example I have to run.
Now it is not working, but when it works, it is not clear which code I will have to use.

Maybe I lost some important information.
Is there documentation explaining this?

Thanks, again!
Andre

Greg-DB
Dropbox Staff

Thanks for the additional information. Unfortunately since that error isn't referencing Dropbox, I'm afraid I can't be of much help with that specifically. I recommend working through the list of potential causes it cites.

 

Anyway, thanks for the feedback. I understand how the Android example could certainly use more detailed documentation. For reference, to set up an app to use the SDK like the sample app does:

 

- Your AndroidManifest.xml should be set up as shown here.

 

- You start the flow by calling startOAuth2Authentication as shown here.

- You complete the flow by calling getOAuth2Token as shown here.

- Your app can store and re-use the resulting access token for that user, as the example does here.

- Once you have an access token, you can make a client as shown here.

- With a client, you can make whatever calls you want. The different pieces of functionality in the Android sample are broken out in different files listed here.

Andre_LB
Explorer | Level 3

Hi Greg,
thanks again for your prompt reply.

I tried to remove the Sync error but I have not been able.
You are saying that this error is not referencing Dropbox (and for this reason it is difficult for you to help me).
But my feeling is that this error is releted the downloaded codes and settings.
For this reason I am not able to fix it.
So I abandoned this way.


---------------------------------------
Now I am straight using my app.
1) I updated my AndroidManifest.xml as you suggested.
Please, note that I do not have the "OpenWithActivity" activity section in it.

2) I call the authentication.
For this reason, in a class (className) I added (conditioned to a botton) the following call:-
Auth.startOAuth2Authentication(className.this, ACCESS_KEY_NAME);

ACCESS_KEY_NAME is, of course, my personal key.

3) For completing the flow, as you suggested, I added the onResume method for calling getOAuth2Token.
Please, note that I took the onResume method from DropboxActivity class
(not from UserActivity one).

4) Since I have got an error for "initAndLoadData" missing, I commented these two calls.

I run this app and the result is:-
Unfortunately, className has stopped

Well, I really hope that you could help me.
I do not hide you that I am losing any hope.
Thank you very much, in advance,
Andre

chirstius
Dropbox Staff

Hello @Andre_LB,

 

I think it would be very helpful for you to post some actual code samples of your Activities/Classes at this point rather than just describing the process.

 

This would help replicate the issue or at least make it easier to potentially identify issues with the authorization flow.

 

Would you be able to provide your manifest.xml and any relevant classes - properly sanitized of keys/tokens/etc. - for review?

 

Thanks,

 

-Chuck

Andre_LB
Explorer | Level 3

Hi Chuck,
thank you very much for your reply and suggestion.

In the mean time, there have been a few progresses. With the attached code, I am able to start and complete the flow. Also, to store and re-use the resulting access token.
It seems to me have obtained an access token but I am not able to make a client.

Indeed, when I add the "requestConfig" setting I have the following error:-
error: cannot access OkHttpClient
class file for okhttp3.OkHttpClient not found


I hope that this time to be easer for you to help me.
But I have another issue.
When I'll have made a client, it is still not clear how may I use it.
I mean, I would like to download/upload a file from/to a Dropbox folder of mine.
Well, how can I perform it?

 

Thank you very much, in advance.
Kind Regards,
Andre

 

public class PrvDef extends AppCompatActivity {

private static DbxClientV2 sDbxClient;
public Button auth_but;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_prv_def);

auth_but = (Button) findViewById(R.id.login_button);
auth_but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Auth.startOAuth2Authentication(PrvDef.this, getString(R.string.app_key));
}
});
}


@Override
protected void onResume() {
super.onResume();

if (hasToken()) {
findViewById(R.id.login_button).setVisibility(View.GONE);
findViewById(R.id.email_text).setVisibility(View.VISIBLE);
findViewById(R.id.name_text).setVisibility(View.VISIBLE);
findViewById(R.id.type_text).setVisibility(View.VISIBLE);
findViewById(R.id.files_button).setEnabled(true);
findViewById(R.id.open_with).setEnabled(true);
} else {
findViewById(R.id.login_button).setVisibility(View.VISIBLE);
findViewById(R.id.email_text).setVisibility(View.GONE);
findViewById(R.id.name_text).setVisibility(View.GONE);
findViewById(R.id.type_text).setVisibility(View.GONE);
findViewById(R.id.files_button).setEnabled(false);
findViewById(R.id.open_with).setEnabled(false);
}
}
protected boolean hasToken() {
SharedPreferences prefs = getSharedPreferences("dropbox-sample", MODE_PRIVATE);
String accessToken = prefs.getString("access-token", null);
if (accessToken == null) {
accessToken = Auth.getOAuth2Token();
if (accessToken != null) {
prefs.edit().putString("access-token", accessToken).apply();
}
}
//-- requestConfig setting --------------------------------------------------------
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("examples-v2-demo")
.withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
.build();
sDbxClient = new DbxClientV2(requestConfig, accessToken);
return accessToken != null;
}

}

========================= Manifest =====================================
<?
xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rram.prvdef">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PrvDef">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>

<!-- Change this to be db- followed by your app key -->
<data android:scheme="db-..my app key ..." />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

</application>

</manifest>

 

chirstius
Dropbox Staff

@Andre_LB,

 

The issue regarding OkHttpClient not being found seems like it is a development environment issue, and not directly related to the Dropbox API. Are you getting errors from gradle or maven? Have you tried updating your project, or forcing a clean build? OkHttp is a dependency of the Dropbox SDK and should be included in your build environment when you include the Dropbox SDK. If you have checked out the SDK to build it yourself the dependency is still there and you'd likely see build errors occuring if it were not imported properly. As a test, you could try including the dependency directly (http://square.github.io/okhttp/#download) to see if it gets you past this error. But I'm not sure there is much direct help I can offer you in resolving this issue specifically since it is technically not an API issue.

 

As for how to upload/download a file via the Java SDK on Android there are examples available within the github respository:
Upload: https://github.com/dropbox/dropbox-sdk-java/blob/947f3f5aa9d5903a222d4b9e4ce7ce2c4defc2a4/examples/a...

Download: https://github.com/dropbox/dropbox-sdk-java/blob/947f3f5aa9d5903a222d4b9e4ce7ce2c4defc2a4/examples/a...

 

I hope that gets you a bit further along,

 

-Chuck

Andre_LB
Explorer | Level 3

Hi Chuck,

thank you for your prompt reply.
Lovely, I included the dependency directly, as you suggested, and the error that I had from gradle has disappeared!
 
Now, if I run the app, I have got:-
Unfortunately, PrvDef has stopped.
 
The issue seems to be in client creating command (that is, "sDbxClient = new DbxClientV2(requestConfig, accessToken);" ).
Indeed, if I comment it this issue disappears.
 
I did not change the code (that i previously sent to you).
Let me know, please, if you need more information.
Thank you very much, in advance.
Kind Regards,
Andre

chirstius
Dropbox Staff

@Andre_LB,

 

Again this appears to be a more generic Android development question and not a Dropbox API specific question.

 

I would suggest you take a good look at the sample Android application included in the Java SDK github repository:
https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android/src/main/java/com/dropbox/c...

 

Specifically, you are creating the client within your hasToken() method which seems a dubious place to perform such an action.

 

I suggest following the flow of the sample application carefully and paying attention to the following class:

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

 

And when/where it gets invoked:

 

https://github.com/dropbox/dropbox-sdk-java/search?utf8=%E2%9C%93&q=DropboxClientFactory&type=

 

Good luck,

 

-Chuck

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Andre_LB Explorer | Level 3
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    chirstius Dropbox Staff
What do Dropbox user levels mean?