正如Joel指出的,Onedrive API也支持基於路徑的尋址(除了基於ID的尋址)。所以你不需要文件夾ID。您可以使用Onedrive API(api.onedrive.com)爲獲得特定文件夾的文件/文件夾,如下所示:
String path = "path/to/your/folder"; // no '/' in the end
HttpClient httpClient = new DefaultHttpClient();
// Forming the request
HttpGet httpGet = new HttpGet("https://api.onedrive.com/v1.0/drive/root:/" + path + ":/?expand=children");
httpGet.addHeader("Authorization", "Bearer " + ACCESS_TOKEN);
// Executing the request
HttpResponse response = httpClient.execute(httpGet);
// Handling the response
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n");
}
JSONTokener tokener = new JSONTokener(builder.toString());
JSONObject finalResult = new JSONObject(tokener);
JSONArray fileList = null;
try{
fileList = finalResult.getJSONArray("children");
for (int i = 0; i < fileList.length(); i++) {
JSONObject element = (JSONObject) fileList.get(i);
// do something with element
// Each element is a file/folder in the form of JSONObject
}
} catch (JSONException e){
// do something with the exception
}
欲瞭解更多詳情,請參見here。
OneDrive API(api.onedrive.com)支持基於路徑的尋址。有關更多詳細信息,請參閱https://dev.onedrive.com/misc/addressing.htm。 編輯:根據您的情況,您可能需要查看特殊文件夾 - 特別是在https://dev.onedrive.com/misc/appfolder.htm上記錄的approot特殊文件夾 – Joel