我有一个问题。但我不会说英语。请理解。
我从Dropbox获得了access token
。我想要一个文件列表。
我找不到Dropbox Core API。 请告诉我们如何获取文件列表。
=============================================== =======================
gpgekko //我被告知你必须找到没有所需结果的元数据。
此网址用于导入元数据。
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);
}
答案 0 :(得分:1)
将您的问题标记为“java”后,我建议您尝试按照他们的教程here进行操作。特别是当列出文件夹时 - 他们使用DbxClient.getMetadataWithChildren()。
答案 1 :(得分:0)
以这种方式解决。
我删除参数中的redirect_uri
并在网址末尾添加/dropbox/
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
}
谢谢大家。