Search in sources :

Example 26 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project orgzly-android by orgzly.

the class DropboxClient method getDbxClient.

private DbxClientV2 getDbxClient(String accessToken) {
    String userLocale = Locale.getDefault().toString();
    String clientId = String.format("%s/%s", BuildConfig.APPLICATION_ID, BuildConfig.VERSION_NAME);
    DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder(clientId).withUserLocale(userLocale).build();
    return new DbxClientV2(requestConfig, accessToken);
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig)

Example 27 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project keepass2android by PhilippC.

the class DropboxV2Storage method buildSession.

private void buildSession() {
    String v2Token = getKeyV2();
    if (v2Token != null) {
        dbxClient = new DbxClientV2(requestConfig, v2Token);
        setLoggedIn(true);
        Log.d(TAG, "Creating Dropbox Session with accessToken");
    } else {
        setLoggedIn(false);
        Log.d(TAG, "Creating Dropbox Session without accessToken");
    }
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2)

Example 28 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project syndesis by syndesisio.

the class DropBoxVerifierExtension method verifyCredentials.

@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) {
    String token = (String) parameters.get("accessToken");
    String clientId = (String) parameters.get("clientIdentifier");
    try {
        // Create Dropbox client
        DbxRequestConfig config = new DbxRequestConfig(clientId, Locale.getDefault().toString());
        DbxClientV2 client = new DbxClientV2(config, token);
        client.users().getCurrentAccount();
        client = null;
    } catch (Exception e) {
        builder.error(ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, "Invalid client identifier and/or access token").parameterKey("accessToken").parameterKey("clientIdentifier").build());
    }
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig)

Example 29 with DbxClientV2

use of com.dropbox.core.v2.DbxClientV2 in project jbpm-work-items by kiegroup.

the class DropboxAuth method authorize.

public DbxClientV2 authorize(String clientIdentifier, String accessToken) throws IllegalArgumentException {
    try {
        DbxRequestConfig config = new DbxRequestConfig(clientIdentifier);
        DbxClientV2 client = new DbxClientV2(config, accessToken);
        return client;
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig)

Example 30 with DbxClientV2

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

the class Main method printChanges.

/**
 * Prints changes made to a folder in Dropbox since the given
 * cursor was retrieved.
 *
 * @param dbxClient Dropbox client to use for fetching folder changes
 * @param cursor lastest cursor received since last set of changes
 *
 * @return latest cursor after changes
 */
private static String printChanges(DbxClientV2 client, String cursor) throws DbxApiException, DbxException {
    while (true) {
        ListFolderResult result = client.files().listFolderContinue(cursor);
        for (Metadata metadata : result.getEntries()) {
            String type;
            String details;
            if (metadata instanceof FileMetadata) {
                FileMetadata fileMetadata = (FileMetadata) metadata;
                type = "file";
                details = "(rev=" + fileMetadata.getRev() + ")";
            } else if (metadata instanceof FolderMetadata) {
                FolderMetadata folderMetadata = (FolderMetadata) metadata;
                type = "folder";
                details = folderMetadata.getSharingInfo() != null ? "(shared)" : "";
            } else if (metadata instanceof DeletedMetadata) {
                type = "deleted";
                details = "";
            } else {
                throw new IllegalStateException("Unrecognized metadata type: " + metadata.getClass());
            }
            System.out.printf("\t%10s %24s \"%s\"\n", type, details, metadata.getPathLower());
        }
        // update cursor to fetch remaining results
        cursor = result.getCursor();
        if (!result.getHasMore()) {
            break;
        }
    }
    return cursor;
}
Also used : FileMetadata(com.dropbox.core.v2.files.FileMetadata) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) Metadata(com.dropbox.core.v2.files.Metadata) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) FileMetadata(com.dropbox.core.v2.files.FileMetadata) ListFolderResult(com.dropbox.core.v2.files.ListFolderResult) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata)

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