Search in sources :

Example 31 with DbxException

use of com.dropbox.core.DbxException 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

DbxException (com.dropbox.core.DbxException)31 FileMetadata (com.dropbox.core.v2.files.FileMetadata)14 IOException (java.io.IOException)14 DbxRequestConfig (com.dropbox.core.DbxRequestConfig)10 Metadata (com.dropbox.core.v2.files.Metadata)9 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)8 FolderMetadata (com.dropbox.core.v2.files.FolderMetadata)8 DbxWebAuth (com.dropbox.core.DbxWebAuth)7 File (java.io.File)6 JsonReader (com.dropbox.core.json.JsonReader)5 DeletedMetadata (com.dropbox.core.v2.files.DeletedMetadata)5 ListFolderResult (com.dropbox.core.v2.files.ListFolderResult)5 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 DbxAuthInfo (com.dropbox.core.DbxAuthInfo)4 BufferedReader (java.io.BufferedReader)4 FileOutputStream (java.io.FileOutputStream)4 InputStreamReader (java.io.InputStreamReader)4 Uri (android.net.Uri)3 DbxAppInfo (com.dropbox.core.DbxAppInfo)3