|
| 1 | +# Dropbox Core SDK for Java 6+ |
| 2 | + |
| 3 | +A Java library to access [Dropbox's HTTP-based Core API](https://www.dropbox.com/developers/core/docs). |
| 4 | + |
| 5 | +License: [MIT](License.txt) |
| 6 | + |
| 7 | +This is for web applications. If you want to use Dropbox's API from Android, try the [Sync SDK](https://www.dropbox.com/developers/sync) |
| 8 | + |
| 9 | +[Javadoc.](http://dropbox.github.io/dropbox-sdk-java/api-docs/v1.6.x/) |
| 10 | + |
| 11 | +## Setup |
| 12 | + |
| 13 | +If you're using Maven, then edit your project's "pom.xml" and add this to the `<dependencies>` section: |
| 14 | + |
| 15 | +```xml |
| 16 | +<dependency> |
| 17 | + <groupId>com.dropbox.core</groupId> |
| 18 | + <artifactId>dropbox-core-sdk</artifactId> |
| 19 | + <version>[1.6,1.7)</version> |
| 20 | +</dependency> |
| 21 | +``` |
| 22 | + |
| 23 | +If you aren't using Maven, here are the JARs you need: |
| 24 | +- [Dropbox Core SDK](http://repo1.maven.org/maven2/com/dropbox/core/dropbox-core-sdk/1.6-beta-1/dropbox-core-sdk-1.6-beta-1.jar) |
| 25 | +- [Jackson Core](http://repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.2.2/jackson-core-2.2.2.jar) (JSON parser) |
| 26 | + |
| 27 | +## Get a Dropbox API key |
| 28 | + |
| 29 | +You need a Dropbox API key to make API requests. |
| 30 | + * Go to: [https://www.dropbox.com/developers/apps](https://www.dropbox.com/developers/apps) |
| 31 | + * If you've already registered an app, click on the "Options" link to see the app's API key and secret. |
| 32 | + * Otherwise, click "Create an app" to register an app. Choose "Full Dropbox" or "App Folder" [depending on your needs](https://www.dropbox.com/developers/reference#permissions). |
| 33 | + |
| 34 | +Save the API key to a JSON file called, say, "test.app": |
| 35 | + |
| 36 | +``` |
| 37 | +{ |
| 38 | + "key": "Your Dropbox API app key", |
| 39 | + "secret": "Your Dropbox API app secret" |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +## Using the Dropbox API |
| 44 | + |
| 45 | +Before your app can access a Dropbox user's files, the user must authorize your application using OAuth 2. Successfully completing this authorization flow gives you an _access token_ for the user's Dropbox account, which grants you the ability to make Dropbox API calls to access their files. |
| 46 | + |
| 47 | + * Authorization example for a simple web app: [Web File Browser example](examples/web-file-browser/src/com/dropbox/core/examples/web_file_browser/DropboxAuth.java) |
| 48 | + * Authorization example for a command-line tool: [Command-Line Authorization example](examples/authorize/src/com/dropbox/core/examples/authorize/Main.java) |
| 49 | + |
| 50 | +Once you have an access token, create a [`DbxClient`](http://dropbox.github.io/dropbox-sdk-java/api-docs/v1.6.x/com/dropbox/core/DbxClient.html) and start making API calls. |
| 51 | + |
| 52 | +You only need to perform the authorization process once per user. Once you have an access token for a user, save it somewhere persistent, like in a database. The next time that user visits your app's, you can skip the authorization process and go straight to creating a `DbxClient` and making API calls. |
| 53 | + |
| 54 | +## Running the examples |
| 55 | + |
| 56 | +Prerequisites: Apache Maven |
| 57 | + |
| 58 | +1. Download this repository. |
| 59 | +2. Save your Dropbox API key in a file called "test.app". See: [Get a Dropbox API key](#get-a-dropbox-api-key), above. |
| 60 | +3. `mvn install` |
| 61 | +4. `mvn -f examples/pom.xml compile` |
| 62 | + |
| 63 | +### authorize |
| 64 | + |
| 65 | +This examples runs through the OAuth 2 authorization flow. |
| 66 | + |
| 67 | +``` |
| 68 | +cd examples |
| 69 | +./run authorize test.app test.auth |
| 70 | +``` |
| 71 | + |
| 72 | +This produces a file named "test.auth" that has the access token. This file can be passed in to the other examples. |
| 73 | + |
| 74 | +### account-info |
| 75 | + |
| 76 | +A trivial example that calls the /account/info API endpoint. |
| 77 | + |
| 78 | +``` |
| 79 | +cd examples |
| 80 | +./run account-info test.auth |
| 81 | +``` |
| 82 | + |
| 83 | +(You must first generate "test.auth" using the "authorize" example above.) |
| 84 | + |
| 85 | +### web-file-browser |
| 86 | + |
| 87 | +A 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. |
| 88 | + |
| 89 | +Prerequisite: In the Dropbox API [app configuration console](https://www.dropbox.com/developers/apps), you need to add "http://localhost:5000/dropbox-auth-finish" to the list of allowed redirect URIs. |
| 90 | + |
| 91 | +``` |
| 92 | +cd examples |
| 93 | +./run web-file-browser 5000 test.app web-file-browser.db |
| 94 | +``` |
0 commit comments