本文整理汇总了Java中com.dropbox.core.v2.DbxClientV2类的典型用法代码示例。如果您正苦于以下问题:Java DbxClientV2类的具体用法?Java DbxClientV2怎么用?Java DbxClientV2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DbxClientV2类属于com.dropbox.core.v2包,在下文中一共展示了DbxClientV2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: syncUploadFile
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
public Object syncUploadFile(DbxClientV2 mDbxClient, String localUri, String remoteFolder) {
Log.d(TAG, "localUri: " + localUri);
File localFile = new File(localUri);
if (localFile.exists()) {
// Note - this is not ensuring the name is a valid dropbox file name
String remoteFileName = localFile.getName();
try (InputStream inputStream = new FileInputStream(localFile)) {
return mDbxClient.files().uploadBuilder(remoteFolder + "/" + remoteFileName)
.withMode(WriteMode.OVERWRITE).uploadAndFinish(inputStream);
} catch (Exception e) {
Log.e(TAG, "stringUploadFile", e);
return e;
}
}
return null;
}
示例2: buildSession
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
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");
}
}
示例3: syncWorldToDropbox
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
/**
* Syncs the current World's files to the user's Dropbox account.
*
* <p>
* If the user has not yet linked a Dropbox account, they will be asked to authenticate
* their account.
* </p>
*
* <p>
* If an error occurs while syncing files, a message will be displayed.
* </p>
*/
private void syncWorldToDropbox() {
if (!(AppPreferences.dropboxAccessTokenExists(this))) {
Auth.startOAuth2Authentication(getApplicationContext(), DROPBOX_APP_KEY);
// Since the Authentication Activity interrupts the flow of this method,
// the actual syncing should occur when the user returns to this Activity after
// authentication.
syncWorldToDropboxOnResume = true;
} else {
new AlertDialog.Builder(this)
.setTitle(this.getString(R.string.confirmBackupToDropboxTitle, worldName))
.setMessage(this.getString(R.string.confirmBackupToDropbox, worldName))
.setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String accessToken = getDropboxAccessToken();
DbxClientV2 client = getDropboxClient(accessToken);
File worldDirectory = FileRetriever.getWorldDirectory(worldName);
new UploadToDropboxTask(client, worldDirectory, ArticleListActivity.this).execute();
}})
.setNegativeButton(android.R.string.no, null).show();
}
}
示例4: append
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
/** */
private void append(String res, DbxClientV2 client) throws DbxException, IOException {
File tmp = createTmpFile();
try (FileOutputStream out = new FileOutputStream(tmp)) {
client.files().download(dropboxPath).download(out);
}
writeResults(res, tmp);
try (FileInputStream in = new FileInputStream(tmp)) {
client.files().uploadBuilder(dropboxPath).withMode(WriteMode.OVERWRITE).uploadAndFinish(in);
}
if (!tmp.delete())
System.out.println("Failed to delete " + tmp.getAbsolutePath());
System.out.println("Uploaded benchmark results to: " + dropboxUrl);
}
示例5: getFragment
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
@Override
protected AbstractFilePickerFragment<Metadata> getFragment(@Nullable final String startPath,
final int mode, final boolean allowMultiple,
final boolean allowCreateDir, final boolean allowExistingFile,
final boolean singleClick) {
DropboxFilePickerFragment fragment = null;
if (!dropboxHelper.authenticationFailed(this)) {
DbxClientV2 dropboxClient = dropboxHelper.getClient(this);
if (dropboxClient != null) {
fragment = new DropboxFilePickerFragment(dropboxClient);
fragment.setArgs(startPath, mode, allowMultiple, allowCreateDir, allowExistingFile, singleClick);
}
}
return fragment;
}
示例6: determineDropboxLink
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
private String determineDropboxLink(DjConfiguration conf) {
DbxClientV2 client = getDbxClient();
try {
String url;
DbxUserSharingRequests share = client.sharing();
ListSharedLinksResult result = share.listSharedLinksBuilder().withPath(dboxFilePath).start();
List<SharedLinkMetadata> links = result.getLinks();
if(links.size() > 0) {
url = links.get(0).getUrl();
} else {
SharedLinkSettings settings = new SharedLinkSettings(RequestedVisibility.PUBLIC, null, null);
SharedLinkMetadata metadata = share.createSharedLinkWithSettings(dboxFilePath, settings);
url = metadata.getUrl();
}
return url.replace("?dl=0", "?raw=1");
} catch (DbxException e) {
logger.error("Can't create dropbox link", e);
return null;
}
}
示例7: deleteRoot
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
@BeforeSuite
@AfterSuite(alwaysRun=true)
public static void deleteRoot() throws Exception {
// always use standard HTTP requestor for delete root
DbxClientV2 client = newClientV2(
newRequestConfig()
.withHttpRequestor(newStandardHttpRequestor())
);
try {
client.files().delete(RootContainer.ROOT);
} catch (DeleteErrorException ex) {
if (ex.errorValue.isPathLookup() &&
ex.errorValue.getPathLookupValue().isNotFound()) {
// ignore
} else {
throw ex;
}
}
}
示例8: main
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
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;
}
DbxClientV2 client = createClient(args[0]);
runTest(client, Main::testBasicSerialization, "testBasicSerialization");
runTest(client, Main::testEnumeratedSubtypeSerialization, "testEnumeratedSubtypeSerialization");
runTest(client, Main::testErrorSerialization, "testErrorSerialization");
}
示例9: getDbxClient
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
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);
}
示例10: readFile
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
@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);
}
示例11: getClient
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
/**
*
* get connection client
*/
@Override
public DbxClientV2 getClient(){
DbxRequestConfig config = DbxRequestConfig.newBuilder(appId).withAutoRetryEnabled(3).withUserLocaleFrom(Locale.ITALY).build();
return new DbxClientV2(config, accessToken);
}
示例12: dropboxGetFiles
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
public static List<String> dropboxGetFiles(String code) {
DbxRequestConfig config = new DbxRequestConfig("Media Information Service Configuration");
DbxClientV2 client = new DbxClientV2(config, code);
ListFolderResult result = null;
List<String> elements = new LinkedList<String>();
try {
result = client.files().listFolderBuilder("/media").withRecursive(true).start();
while (true) {
for (Metadata metadata : result.getEntries()) {
if (metadata instanceof FileMetadata) {
elements.add(metadata.getName());
}
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
}
//System.out.println(elements.toString());
} catch (DbxException e) {
e.printStackTrace();
}
return elements;
}
示例13: getClient
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
public static DbxClientV2 getClient(String ACCESS_TOKEN) {
// Create Dropbox client
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("Flashcard Maker")
.withHttpRequestor(new OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
.build();
DbxClientV2 client = new DbxClientV2(requestConfig, ACCESS_TOKEN);
return client;
}
示例14: logChangedFiles
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
public void logChangedFiles(final String userId) throws Exception {
final String accessToken = getTokenAndCheckIsTokenExists(userId);
final DbxClientV2 client = new DbxClientV2(requestConfig, accessToken);
final String cursor = userTokenRepository.getValue(CURSORS_HASH_KEY, userId);
final ListFolderResult listFolderContinue = client.files().listFolderContinue(cursor);
logChangedFilesOfUser(userId, listFolderContinue);
}
示例15: finishAuthAndSaveUserDetails
import com.dropbox.core.v2.DbxClientV2; //导入依赖的package包/类
public void finishAuthAndSaveUserDetails(final HttpSession session, final Map<String, String[]> parameterMap) throws Exception {
final DbxSessionStore csrfTokenStore = new DbxStandardSessionStore(session, dropboxConfigProp.getSessionStore().getKey());
final DbxAuthFinish authFinish = auth.finishFromRedirect(dropboxConfigProp.getRedirectUri(), csrfTokenStore, parameterMap);
final String accessToken = authFinish.getAccessToken();
final DbxClientV2 client = new DbxClientV2(requestConfig, accessToken);
final String userId = authFinish.getUserId();
final ListFolderResult listFolderResult = client.files().listFolderBuilder("").withRecursive(true).start();
saveAccessTokenAndActualCursor(userId, accessToken, listFolderResult);
}