-
Notifications
You must be signed in to change notification settings - Fork 445
/
Main.java
68 lines (59 loc) · 2.3 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.dropbox.core.examples.account_info;
import com.dropbox.core.DbxAuthInfo;
import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.DbxWebAuth;
import com.dropbox.core.json.JsonReader;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.users.FullAccount;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* An example command-line application that runs through the web-based OAuth
* flow (using {@link DbxWebAuth}).
*/
public class Main
{
public static void main(String[] args)
throws IOException
{
// Only display important log messages.
Logger.getLogger("").setLevel(Level.WARNING);
if (args.length != 1) {
System.out.println("");
System.out.println("Usage: COMMAND <auth-file>");
System.out.println("");
System.out.println(" <auth-file>: An \"auth file\" that contains the information necessary to make");
System.out.println(" an authorized Dropbox API request. Generate this file using the \"authorize\"");
System.out.println(" example program.");
System.out.println("");
System.exit(1);
return;
}
String argAuthFile = args[0];
// Read auth info file.
DbxAuthInfo authInfo;
try {
authInfo = DbxAuthInfo.Reader.readFromFile(argAuthFile);
}
catch (JsonReader.FileLoadException ex) {
System.err.println("Error loading <auth-file>: " + ex.getMessage());
System.exit(1); return;
}
// Create a DbxClientV1, which is what you use to make API calls.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-account-info");
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, authInfo.getAccessToken(), authInfo.getHost());
// Make the /account/info API call.
FullAccount dbxAccountInfo;
try {
dbxAccountInfo = dbxClient.users()
.getCurrentAccount();
}
catch (DbxException ex) {
System.err.println("Error making API call: " + ex.getMessage());
System.exit(1); return;
}
System.out.print(dbxAccountInfo.toStringMultiline());
}
}