Skip to content

Commit 0a839fe

Browse files
author
Karl Rieb
committed
Add online tutorial code as an example.
1 parent adafa12 commit 0a839fe

File tree

18 files changed

+106
-8
lines changed

18 files changed

+106
-8
lines changed

ChangeLog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Add example from online tutorial.
12

23
---------------------------------------------
34
2.0.0 (2016-03-03)

ReadMe.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ This produces a file named "test.auth" that has the access token. This file can
7272

7373
### account-info
7474

75-
A trivial example that calls the /account/info API endpoint.
75+
A simple example that fetches and displays information about the account associated with the access token.
7676

7777
```
7878
cd examples
@@ -81,6 +81,21 @@ cd examples
8181

8282
(You must first generate "test.auth" using the "authorize" example above.)
8383

84+
### longpoll
85+
86+
An example of how to watch for changes in a Dropbox directory.
87+
88+
```
89+
cd examples
90+
./run longpoll test.auth "/path/to/watch"
91+
```
92+
93+
(You must first generate "test.auth" using the "authorize" example above.)
94+
95+
### tutorial
96+
97+
The example from our (online tutorial)[https://www.dropbox.com/developers/documentation/java#tutorial]. Unlike the other examples, this example is not meant to be run without modification.
98+
8499
### upload-file
85100

86101
Uploads a file to Dropbox.

examples/account-info/src/com/dropbox/core/examples/account_info/Main.java renamed to examples/account-info/src/main/java/com/dropbox/core/examples/account_info/Main.java

File renamed without changes.

examples/authorize/src/com/dropbox/core/examples/authorize/Main.java renamed to examples/authorize/src/main/java/com/dropbox/core/examples/authorize/Main.java

File renamed without changes.

examples/longpoll/src/com/dropbox/core/examples/longpoll/Main.java renamed to examples/longpoll/src/main/java/com/dropbox/core/examples/longpoll/Main.java

File renamed without changes.

examples/pom.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
<packaging>pom</packaging>
1313

1414
<modules>
15-
<module>authorize</module>
1615
<module>account-info</module>
16+
<module>authorize</module>
1717
<module>longpoll</module>
18+
<module>tutorial</module>
19+
<module>upgrade-oauth1-token</module>
1820
<module>upload-file</module>
1921
<module>web-file-browser</module>
20-
<module>upgrade-oauth1-token</module>
2122
</modules>
2223

2324
<dependencies>
@@ -38,9 +39,6 @@
3839
</repositories>
3940

4041
<build>
41-
<sourceDirectory>src</sourceDirectory>
42-
<testSourceDirectory>test</testSourceDirectory>
43-
4442
<pluginManagement>
4543
<plugins>
4644
<plugin>
@@ -63,8 +61,8 @@
6361
<groupId>org.apache.maven.plugins</groupId>
6462
<artifactId>maven-compiler-plugin</artifactId>
6563
<configuration>
66-
<source>1.6</source>
67-
<target>1.6</target>
64+
<source>8</source>
65+
<target>8</target>
6866
<encoding>UTF-8</encoding>
6967
</configuration>
7068
</plugin>

examples/tutorial/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

examples/tutorial/ReadMe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Tutorial Example
2+
3+
This repo contains the example from our [online tutorial](https://www.dropbox.com/developers/documentation/java#tutorial).
4+
5+
To run this example, please replace `"<ACCESS TOKEN>"` in `Main.java` with your access token. See the online tutorial for more details on how to generate an access token.
6+

examples/tutorial/pom.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
4+
http://maven.apache.org/maven-v4_0_0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<name>Tutorial Example (Dropbox Core API SDK)</name>
8+
<artifactId>examples-tutorial</artifactId>
9+
<packaging>jar</packaging>
10+
11+
<parent>
12+
<groupId>com.dropbox.core</groupId>
13+
<artifactId>examples</artifactId>
14+
<version>0-SNAPSHOT</version>
15+
<relativePath>../pom.xml</relativePath>
16+
</parent>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.apache.maven.plugins</groupId>
22+
<artifactId>maven-dependency-plugin</artifactId>
23+
<executions>
24+
<execution>
25+
<phase>compile</phase>
26+
<goals>
27+
<goal>build-classpath</goal>
28+
</goals>
29+
</execution>
30+
</executions>
31+
</plugin>
32+
</plugins>
33+
</build>
34+
</project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.dropbox.core.examples.tutorial;
2+
3+
import com.dropbox.core.DbxException;
4+
import com.dropbox.core.DbxRequestConfig;
5+
import com.dropbox.core.v2.DbxClientV2;
6+
import com.dropbox.core.v2.files.FileMetadata;
7+
import com.dropbox.core.v2.files.Metadata;
8+
import com.dropbox.core.v2.users.FullAccount;
9+
10+
import java.util.List;
11+
12+
import java.io.FileInputStream;
13+
import java.io.InputStream;
14+
import java.io.IOException;
15+
16+
public class Main {
17+
private static final String ACCESS_TOKEN = "<ACCESS TOKEN>";
18+
19+
public static void main(String args[]) throws DbxException, IOException {
20+
// Create Dropbox client
21+
DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
22+
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
23+
24+
// Get current account info
25+
FullAccount account = client.users().getCurrentAccount();
26+
System.out.println(account.getName().getDisplayName());
27+
28+
// Get files and folder metadata from Dropbox root directory
29+
List<Metadata> entries = client.files().listFolder("").getEntries();
30+
for (Metadata metadata : entries) {
31+
System.out.println(metadata.getPathLower());
32+
}
33+
34+
// Upload "test.txt" to Dropbox
35+
try (InputStream in = new FileInputStream("test.txt")) {
36+
FileMetadata metadata = client.files().uploadBuilder("/test.txt")
37+
.uploadAndFinish(in);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)