-
Notifications
You must be signed in to change notification settings - Fork 444
/
Main.java
73 lines (64 loc) · 2.6 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
69
70
71
72
73
package com.dropbox.core.examples.account_info;
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.oauth.DbxCredential;
import com.dropbox.core.stone.StoneDeserializerLogger;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.users.FullAccount;
import com.dropbox.core.v2.users.Name;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* An example command-line application that grab access token and refresh token from credential
* file, and then call APIV2. If the access token has expired, SDK will automatically refresh and
* get a new one, and store them into the original DbxCredential object.
*/
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");
System.out.println(" \"authorize\" example program.");
System.out.println("");
System.exit(1);
return;
}
String argAuthFile = args[0];
// Use DbxCredential instead of DbxAuthInfo.
DbxCredential credential;
try {
credential = DbxCredential.Reader.readFromFile(argAuthFile);
}
catch (JsonReader.FileLoadException ex) {
System.err.println("Error loading <auth-file>: " + ex.getMessage());
System.exit(1); return;
}
// Create a DbxClientV2, which is what you use to make API calls.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-account-info");
// Use DbxCredential to create dbx client.
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, credential);
// 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());
}
}