Android上的Dropbox API - 使用Token从Apps文件夹下载文件

时间:2017-05-15 16:36:11

标签: android dropbox dropbox-api

我生成了一个访问令牌,可以为我自己的帐户进行API调用,而无需通过授权流程。我找到了这个Dropbox files Get API,但我不知道如何使用它。

我尝试了这段代码,但它似乎不起作用:

    // Authentication with Token
    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys);
    mDBApi = new DropboxAPI<AndroidAuthSession>(session);
    mDBApi.getSession().setOAuth2AccessToken(ACCESS_TOKEN);

    // Upload a file to Apps folder
    File file = new File("working-draft.txt");

    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
        DropboxAPI.Entry response = mDBApi.putFile("/magnum-opus.txt", inputStream,
                file.length(), null, null);
        Log.i("DbExampleLog", "The uploaded file's rev is: " + response.rev);

    } catch (Exception e) {
        e.printStackTrace();
    }

如何使用令牌密钥直接上传并下载到Apps文件夹? 还有办法打印我的Apps文件夹中的所有文件列表吗?

1 个答案:

答案 0 :(得分:2)

文档很差。我在Github上找到了以下示例,它帮助了我: https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/android/src/main/java/com/dropbox/core/examples/android

在gradle中     编译&#39; com.dropbox.core:dropbox-core-sdk:3.0.2&#39;或者是最新的

密钥和密钥被写入JSON文件+您需要使用app密钥添加到清单中的条目。只需按照显示占位符的示例进行操作即可。

完成握手并获得访问令牌后

DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder("your identifier")
            .withHttpRequestor(new 
OkHttp3Requestor(OkHttp3Requestor.defaultOkHttpClient()))
            .build();

dbxClient = new DbxClientV2(requestConfig, accessToken);

dbxClient.files().[operation e.g. upload\download\file listing]
相关问题