Search in sources :

Example 46 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.

the class DbxClientV2IT method testAccountInfo.

@Test
public void testAccountInfo() throws Exception {
    DbxClientV2 client = ITUtil.newClientV2();
    FullAccount full = client.users().getCurrentAccount();
    assertThat(full).isNotNull();
    assertThat(full.getName()).isNotNull();
    assertThat(full.getAccountId()).isNotNull();
    BasicAccount basic = client.users().getAccount(full.getAccountId());
    assertThat(basic).isNotNull();
    assertThat(basic.getName()).isNotNull();
    assertThat(basic.getAccountId()).isEqualTo(full.getAccountId());
}
Also used : BasicAccount(com.dropbox.core.v2.users.BasicAccount) FullAccount(com.dropbox.core.v2.users.FullAccount) Test(org.testng.annotations.Test)

Example 47 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.

the class Main method 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 DbxClientV2, 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());
    StoneDeserializerLogger.LoggerCallback callback = (o, s) -> {
        System.out.println("This is from StoneDeserializerLogger: ");
        System.out.println(s);
    };
    StoneDeserializerLogger.registerCallback(Name.class, callback);
    // 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.println("This is from main: ");
    System.out.print(dbxAccountInfo.toStringMultiline());
}
Also used : DbxWebAuth(com.dropbox.core.DbxWebAuth) DbxException(com.dropbox.core.DbxException) Name(com.dropbox.core.v2.users.Name) DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) FullAccount(com.dropbox.core.v2.users.FullAccount) DbxAuthInfo(com.dropbox.core.DbxAuthInfo) IOException(java.io.IOException) JsonReader(com.dropbox.core.json.JsonReader) Logger(java.util.logging.Logger) StoneDeserializerLogger(com.dropbox.core.stone.StoneDeserializerLogger) Level(java.util.logging.Level) DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) DbxAuthInfo(com.dropbox.core.DbxAuthInfo) JsonReader(com.dropbox.core.json.JsonReader) StoneDeserializerLogger(com.dropbox.core.stone.StoneDeserializerLogger) FullAccount(com.dropbox.core.v2.users.FullAccount) DbxException(com.dropbox.core.DbxException)

Example 48 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project dropbox-sdk-java by dropbox.

the class Main method 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());
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) DbxCredential(com.dropbox.core.oauth.DbxCredential) JsonReader(com.dropbox.core.json.JsonReader) FullAccount(com.dropbox.core.v2.users.FullAccount) DbxException(com.dropbox.core.DbxException)

Aggregations

DbxClientV2 (com.dropbox.core.v2.DbxClientV2)25 FileMetadata (com.dropbox.core.v2.files.FileMetadata)24 Test (org.testng.annotations.Test)19 DbxRequestConfig (com.dropbox.core.DbxRequestConfig)18 HttpRequestor (com.dropbox.core.http.HttpRequestor)15 Metadata (com.dropbox.core.v2.files.Metadata)15 DbxException (com.dropbox.core.DbxException)10 DbxCredential (com.dropbox.core.oauth.DbxCredential)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 JsonReader (com.dropbox.core.json.JsonReader)5 ListFolderResult (com.dropbox.core.v2.files.ListFolderResult)5 FullAccount (com.dropbox.core.v2.users.FullAccount)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 DbxAuthInfo (com.dropbox.core.DbxAuthInfo)4 DeletedMetadata (com.dropbox.core.v2.files.DeletedMetadata)4 FolderMetadata (com.dropbox.core.v2.files.FolderMetadata)4 IOException (java.io.IOException)4 Date (java.util.Date)4 NetworkIOException (com.dropbox.core.NetworkIOException)3 ProgressListener (com.dropbox.core.util.IOUtil.ProgressListener)3