在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:dropbox/dropbox-sdk-java开源软件地址:https://github.com/dropbox/dropbox-sdk-java开源编程语言:Java 82.0%开源软件介绍:Dropbox Core SDK for JavaA Java library to access Dropbox's HTTP-based Core API v2. This SDK also supports the older Core API v1, but that support will be removed at some point. License: MIT Documentation: Javadocs SetupJava VersionThe current release of Dropbox SDK Java supports Java 11+. If you are running Java 8 and want to use the SDK, you should user version Add a dependency on the Dropbox Java SDK to your projectIf you're using Maven, then edit your project's "pom.xml" and add this to the <dependency>
<groupId>com.dropbox.core</groupId>
<artifactId>dropbox-core-sdk</artifactId>
<version>5.2.0</version>
</dependency> If you are using Gradle, then edit your project's "build.gradle" and add this to the dependencies {
// ...
implementation 'com.dropbox.core:dropbox-core-sdk:5.2.0'
} You can also download the Java SDK JAR and and its required dependencies directly from the latest release page. Note that the distribution artifacts on the releases pages do not contain optional dependencies. Dropbox for Java tutorialA good way to start using the Java SDK is to follow this quick tutorial. Just make sure you have the the Java SDK installed first! Register a Dropbox API appTo use the Dropbox API, you'll need to register a new app in the App Console. Select Dropbox API app and choose your app's permission. You'll need to use the app key created with this app to access API v2. Link an accountIn order to make calls to the API, you'll need an instance of the Dropbox object. To instantiate, pass in the access token for the account you want to link. (Tip: You can generate an access token for your own account through the App Console). import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
public class Main {
private static final String ACCESS_TOKEN = "<ACCESS TOKEN>";
public static void main(String args[]) throws DbxException {
// Create Dropbox client
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/java-tutorial").build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
}
} Test it out to make sure you've linked the right account: // Get current account info
FullAccount account = client.users().getCurrentAccount();
System.out.println(account.getName().getDisplayName()); Try some API requestsYou can use the Dropbox object you instantiated above to make API calls. Try out a request to list the contents of a folder. // Get files and folder metadata from Dropbox root directory
ListFolderResult result = client.files().listFolder("");
while (true) {
for (Metadata metadata : result.getEntries()) {
System.out.println(metadata.getPathLower());
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
} Try uploading a file to your Dropbox. // Upload "test.txt" to Dropbox
try (InputStream in = new FileInputStream("test.txt")) {
FileMetadata metadata = client.files().uploadBuilder("/test.txt")
.uploadAndFinish(in);
} Full Example Snippetimport com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.ListFolderResult;
import com.dropbox.core.v2.files.Metadata;
import com.dropbox.core.v2.users.FullAccount;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
public class Main {
private static final String ACCESS_TOKEN = "<ACCESS TOKEN>";
public static void main(String args[]) throws DbxException, IOException {
// Create Dropbox client
DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
// Get current account info
FullAccount account = client.users().getCurrentAccount();
System.out.println(account.getName().getDisplayName());
// Get files and folder metadata from Dropbox root directory
ListFolderResult result = client.files().listFolder("");
while (true) {
for (Metadata metadata : result.getEntries()) {
System.out.println(metadata.getPathLower());
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
}
// Upload "test.txt" to Dropbox
try (InputStream in = new FileInputStream("test.txt")) {
FileMetadata metadata = client.files().uploadBuilder("/test.txt")
.uploadAndFinish(in);
}
}
} Full examplesSome more complete examples can be found here:
To try out running this examples, please follow the instructions below. Save your Dropbox API keySave your Dropbox API key to a JSON file called, say, "test.app":
App key and secret can be found in you app page in App Console. Building from source
The output will be in "build/". Running the examples
authorizeThis examples runs through the OAuth 2 authorization flow.
This produces a file named "test.auth" that has the access token. This file can be passed in to the other examples. account-infoA simple example that fetches and displays information about the account associated with the access token.
(You must first generate "test.auth" using the "authorize" example above.) longpollAn example of how to watch for changes in a Dropbox directory.
(You must first generate "test.auth" using the "authorize" example above.) upload-fileUploads a file to Dropbox. The example includes regular and chunked file uploads.
(You must first generate "test.auth" using the "authorize" example above.) web-file-browserA tiny web app that runs through the OAuth 2 authorization flow and then uses Dropbox API calls to let the user browse their Dropbox files. Prerequisite: In the Dropbox API app configuration console, you need to add "http://localhost:5000/dropbox-auth-finish" to the list of allowed redirect URIs.
Running the integration tests
To run individual tests, use the
Android 11 UpdatesIn the event you are using the Android-specific code in this library (i.e. the code in When targeting/running on Android 11 (targetSdk 30 in your app's To resolve the issue, add the following to your
We are working on pulling out this Android-specific code into its own android library with an FAQ
When I use |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论