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

Dropbox API on Android - Using Token to download file from Apps folder

我生成了一个访问令牌,以便能够 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 文件夹中所有文件的列表?

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

在gradle 编译 'com.dropbox.core:dropbox-core-sdk:3.0.2' 或最新的

密钥和秘密被写入 JSON 文件 + 您需要使用应用程序密钥将一个条目添加到清单中。只需按照显示占位符的示例即可。

完成握手并取回访问令牌后

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]