/** * Builds an instance of {@link DbxRequestConfig} with this builder's configured parameters * or defaults. * * @return new {@code DbxRequestConfig} instance. */ public DbxRequestConfig build() { return new DbxRequestConfig(clientIdentifier, userLocale, httpRequestor, maxRetries); } }
DbxOAuth1Upgrader upgrader; DbxOAuth1AccessToken oAuth1AccessToken; try { DbxRequestConfig requestConfig = new DbxRequestConfig("Your App", Locale.getDefault().toString()); DbxAppInfo appInfo = new DbxAppInfo(DROPBOX_APP_KEY, DROPBOX_APP_SECRET); upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo); oAuth1AccessToken = new DbxOAuth1AccessToken(oauth1AccessKey, oauth1AccessSecret); String newToken = upgrader.createOAuth2AccessToken(oAuth1AccessToken); upgrader.disableOAuth1AccessToken(oAuth1AccessToken); return newToken; } catch (Exception e) { //deal with it }
/** * 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); }
@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); }
DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0", Locale.getDefault().toString()); DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
@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); } } };
DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0", Locale.getDefault().toString()); DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
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 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); }
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()); } }