Search in sources :

Example 1 with FullAccount

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

the class Main method testBasicSerialization.

private static void testBasicSerialization(DbxClientV2 client) throws DbxException, IOException {
    // Make the /account/info API call.
    FullAccount expected = client.users().getCurrentAccount();
    assertNotNull(expected);
    String accountId = expected.getAccountId();
    assertNotNull(accountId);
    assertNotNull(expected.getName());
    BasicAccount actual = client.users().getAccount(accountId);
    assertNotNull(actual);
    assertEquals(actual.getAccountId(), expected.getAccountId());
    assertEquals(actual.getEmail(), expected.getEmail());
}
Also used : BasicAccount(com.dropbox.core.v2.users.BasicAccount) FullAccount(com.dropbox.core.v2.users.FullAccount)

Example 2 with FullAccount

use of com.dropbox.core.v2.users.FullAccount 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 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());
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) DbxAuthInfo(com.dropbox.core.DbxAuthInfo) JsonReader(com.dropbox.core.json.JsonReader) FullAccount(com.dropbox.core.v2.users.FullAccount) DbxException(com.dropbox.core.DbxException)

Example 3 with FullAccount

use of com.dropbox.core.v2.users.FullAccount 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();
    assertNotNull(full);
    assertNotNull(full.getName());
    assertNotNull(full.getAccountId());
    BasicAccount basic = client.users().getAccount(full.getAccountId());
    assertNotNull(basic);
    assertNotNull(basic.getName());
    assertEquals(basic.getAccountId(), full.getAccountId());
}
Also used : BasicAccount(com.dropbox.core.v2.users.BasicAccount) FullAccount(com.dropbox.core.v2.users.FullAccount) Test(org.testng.annotations.Test)

Example 4 with FullAccount

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

the class Main method main.

public static void main(String[] args) throws DbxException, IOException {
    // Create Dropbox client
    DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial");
    DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
    // Get current account info
    FullAccount account = client.users().getCurrentAccount();
    System.out.println(account.getName().getDisplayName());
    // Get files and folder metadata from Dropbox root directory
    ListFolderResult result = client.files().listFolder("");
    while (true) {
        for (Metadata metadata : result.getEntries()) {
            System.out.println(metadata.getPathLower());
        }
        if (!result.getHasMore()) {
            break;
        }
        result = client.files().listFolderContinue(result.getCursor());
    }
    // Upload "test.txt" to Dropbox
    try (InputStream in = new FileInputStream("test.txt")) {
        FileMetadata metadata = client.files().uploadBuilder("/test.txt").uploadAndFinish(in);
    }
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileMetadata(com.dropbox.core.v2.files.FileMetadata) Metadata(com.dropbox.core.v2.files.Metadata) FileMetadata(com.dropbox.core.v2.files.FileMetadata) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) FullAccount(com.dropbox.core.v2.users.FullAccount) FileInputStream(java.io.FileInputStream)

Aggregations

FullAccount (com.dropbox.core.v2.users.FullAccount)4 DbxRequestConfig (com.dropbox.core.DbxRequestConfig)2 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)2 BasicAccount (com.dropbox.core.v2.users.BasicAccount)2 DbxAuthInfo (com.dropbox.core.DbxAuthInfo)1 DbxException (com.dropbox.core.DbxException)1 JsonReader (com.dropbox.core.json.JsonReader)1 FileMetadata (com.dropbox.core.v2.files.FileMetadata)1 ListFolderResult (com.dropbox.core.v2.files.ListFolderResult)1 Metadata (com.dropbox.core.v2.files.Metadata)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Test (org.testng.annotations.Test)1