0

我有个问题。但我英语说得不好。敬请谅解。

我是access token从 Dropbox 那里得到的。我想要一个文件列表。

我找不到Dropbox Core API。请告诉我们如何获取文件列表。

==================================================== =====================

gpgekko// 我被告知你必须找到元数据没有想要的结果。

此 URL 用于导入元数据。

https://api.dropbox.com/1/metadata/<root>/<path>

/<root>/<path>排斥不知道是什么。

JSP 文件,调用此函数。

public void getFiles() throws IOException {
    consoleCheck("getFiles");

    String parameters = "access_token=" + access_token;
    parameters += "&redirect_uri=" + redirect_uri;
    parameters += "&list=true";
    URL url = new URL("https://api.dropbox.com/1/metadata/");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);

    DataOutputStream writer = new DataOutputStream(conn.getOutputStream());
    writer.writeBytes(parameters);
    writer.flush();

    if (writer != null)
        writer.close();

    InputStream inputStream = conn.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    String line;
    StringBuffer stringBuffer = new StringBuffer();

    while ((line = reader.readLine()) != null) {
        stringBuffer.append(line);
        stringBuffer.append('\r');
    }
    JSONObject object = (JSONObject) JSONValue.parse(stringBuffer.toString());
    System.out.println("object => " + object);
}
4

2 回答 2

1

将您的问题标记为“java”后,我建议您尝试在此处按照他们的教程进行操作。特别是在列出文件夹时- 他们使用DbxClient.getMetadataWithChildren()

于 2014-03-11T10:01:22.960 回答
0

这样就解决了。

redirect_uri在参数中删除并/dropbox/在 url 末尾添加

public JSONObject getFiles() throws IOException {
    consoleCheck("getFiles");

    String parameters = "access_token=" + access_token;
    //parameters += "&redirect_uri=" + redirect_uri;
    parameters += "&list=true";
    URL url = new URL("https://api.dropbox.com/1/metadata/dropbox/");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);

    DataOutputStream writer = new DataOutputStream(conn.getOutputStream());
    writer.writeBytes(parameters);
    writer.flush();

    if (writer != null)
        writer.close();

    InputStream inputStream = conn.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
    String line;
    StringBuffer stringBuffer = new StringBuffer();

    while ((line = reader.readLine()) != null) {
        stringBuffer.append(line);
        stringBuffer.append('\r');
    }
    JSONObject object = (JSONObject) JSONValue.parse(stringBuffer.toString());
    //System.out.println("object => " + object);
    return object;
}

结果类型为 JSONObejct。结果值是这样的。

{
"size": "0 bytes",
"hash": "37eb1ba1849d4b0fb0b28caf7ef3af52",
"bytes": 0,
"thumb_exists": false,
"rev": "714f029684fe",
"modified": "Wed, 27 Apr 2011 22:18:51 +0000",
"path": "/Public",
"is_dir": true,
"icon": "folder_public",
"root": "dropbox",
"contents": [
    {
        "size": "0 bytes",
        "rev": "35c1f029684fe",
        "thumb_exists": false,
        "bytes": 0,
        "modified": "Mon, 18 Jul 2011 20:13:43 +0000",
        "client_mtime": "Wed, 20 Apr 2011 16:20:19 +0000",
        "path": "/Public/latest.txt",
        "is_dir": false,
        "icon": "page_white_text",
        "root": "dropbox",
        "mime_type": "text/plain",
        "revision": 220191
    }
],
"revision": 29007
}

谢谢大家。

于 2014-03-12T05:20:19.127 回答