/** * Obtain a new instance of DbxClient and store it in configuration. */ public void createClient() { DbxRequestConfig config = new DbxRequestConfig(clientIdentifier, Locale.getDefault().toString()); this.client = new DbxClientV2(config, accessToken); }
/** * Returns a new {@link DbxClientV2} that performs requests against Dropbox API * user endpoints relative to a namespace without including the namespace as * part of the path variable for every request. * (<a href="https://www.dropbox.com/developers/reference/namespace-guide#pathrootmodes">https://www.dropbox.com/developers/reference/namespace-guide#pathrootmodes</a>). * * <p> This method performs no validation of the namespace ID. </p> * * @param pathRoot the path root for this client, never {@code null}. * * @return Dropbox client that issues requests with Dropbox-API-Path-Root header. * * @throws IllegalArgumentException If {@code pathRoot} is {@code null} */ public DbxClientV2 withPathRoot(PathRoot pathRoot) { if (pathRoot == null) { throw new IllegalArgumentException("'pathRoot' should not be null"); } return new DbxClientV2(_client.withPathRoot(pathRoot)); }
public static DbxClientV2 getDbxClient() { String accessToken = (String) ApplicationSettings.Setting.DROPBOX_TOKEN.getValue(); if (accessToken == null) { JOptionPane.showMessageDialog(null, "The authentication token has not been set.\n" + "Please connect the application to your Dropbox account first!", "Dropbox authentication token not found", JOptionPane.ERROR_MESSAGE ); return null; } return new DbxClientV2(getDbxConfig(), accessToken); }
@Override public ResponseEntity<StreamingResponseBody> readFile(String fileLocation, String imageDir, String id, String fileName) { StreamingResponseBody streamingResponseBody = new StreamingResponseBody() { @Override public void writeTo(OutputStream outputStream) { try { String fileStr = SEPARATOR + imageDir + SEPARATOR + id + SEPARATOR + fileName; DbxRequestConfig config = new DbxRequestConfig(APP_IDENTIFIER); DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN); client.files().download(fileStr).download(outputStream); } catch (Exception e) { logger.error(e.getMessage()); throw new ResourceNotFoundException("Image Not Found : " + id + "/" + fileName); } } }; HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_TYPE, "image/*"); return new ResponseEntity<StreamingResponseBody>(streamingResponseBody, headers, HttpStatus.OK); }
@Override public void writeTo(OutputStream outputStream) { try { String fileStr = SEPARATOR + imageDir + SEPARATOR + id + SEPARATOR + fileName; DbxRequestConfig config = new DbxRequestConfig(APP_IDENTIFIER); DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN); client.files().download(fileStr).download(outputStream); } catch (Exception e) { logger.error(e.getMessage()); throw new ResourceNotFoundException("Image Not Found : " + id + "/" + fileName); } } };
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(); } catch (DbxException e) { builder.error(ResultErrorBuilder .withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, "Invalid client identifier and/or access token") .parameterKey("accessToken").parameterKey("clientIdentifier").build()); } }
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()); } }
private FileMetadata dropBoxSave(String uploadPath, InputStream inputStream)throws Exception{ DbxRequestConfig config = new DbxRequestConfig(APP_IDENTIFIER); DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN); return client.files().uploadBuilder(uploadPath).uploadAndFinish(inputStream); }
/** * Returns a {@link DbxClientV2} that performs requests against Dropbox API * user endpoints as the given team member. * * <p> This method performs no validation of the team member ID. </p> * * @param memberId Team member ID of member in this client's team, never * {@code null}. * * @return Dropbox client that issues requests to user endpoints as the * given team member * * @throws IllegalArgumentException If {@code memberId} is {@code null} */ public DbxClientV2 asMember(String memberId) { if (memberId == null) { throw new IllegalArgumentException("'memberId' should not be null"); } DbxRawClientV2 asMemberClient = new DbxTeamRawClientV2( _client.getRequestConfig(), _client.getHost(), accessToken, _client.getUserId(), memberId, null, null ); return new DbxClientV2(asMemberClient); }
/** * Returns a {@link DbxClientV2} that performs requests against Dropbox API * user endpoints as the given team admin. * * <p> This method performs no validation of the team admin ID. </p> * * @param adminId Team member ID of the admin in client's team, never * {@code null}. * * @return Dropbox client that issues requests to user endpoints as the * given team Admin. * * @throws IllegalArgumentException If {@code adminId} is {@code null} */ public DbxClientV2 asAdmin(String adminId) { if (adminId == null) { throw new IllegalArgumentException("'adminId' should not be null"); } DbxRawClientV2 asAdminClient = new DbxTeamRawClientV2( _client.getRequestConfig(), _client.getHost(), accessToken, _client.getUserId(), null, adminId, null ); return new DbxClientV2(asAdminClient); }
public static void init(String accessToken) { if (sDbxClient == null || DropboxClientFactory.accessToken != accessToken) { DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("upm") .withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient())) .build(); sDbxClient = new DbxClientV2(requestConfig, accessToken); DropboxClientFactory.accessToken = accessToken; } }
private boolean authSession() { String accessToken = MyPreferences.getDropboxAuthToken(context); if (accessToken != null) { if (dropboxClient == null) { DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("financisto") .withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient())) .build(); dropboxClient = new DbxClientV2(requestConfig, accessToken); } return true; } return false; }