根据此处提到的对 DropBox 所做的更改:https://www.dropbox.com/help/16/en
将不再有公共文件夹,而是可以通过共享链接访问文件。
如果您使用 Android DropBox Core Api,则可以通过以下方式检索共享链接:
// Get the metadata for a directory
Entry dirent = mApi.metadata(mPath, 1000, null, true, null);
for (Entry ent : dirent.contents) {
String shareAddress = null;
if (!ent.isDir) {
DropboxLink shareLink = mApi.share(ent.path);
shareAddress = getShareURL(shareLink.url).replaceFirst("https://www", "https://dl");
Log.d(TAG, "dropbox share link " + shareAddress);
}
}
更新:Dheeraj Bhaskar 于 2014 年 7 月 20 日发布
将以下辅助函数与上述函数一起使用。
由于 DropBox 开始发送缩短的链接,因此获得正确的链接有点问题。
目前,我正在使用这种方法:
我们只需加载 URL,按照重定向并获取新 URL。
String getShareURL(String strURL) {
URLConnection conn = null;
String redirectedUrl = null;
try {
URL inputURL = new URL(strURL);
conn = inputURL.openConnection();
conn.connect();
InputStream is = conn.getInputStream();
System.out.println("Redirected URL: " + conn.getURL());
redirectedUrl = conn.getURL().toString();
is.close();
} catch (MalformedURLException e) {
Log.d(TAG, "Please input a valid URL");
} catch (IOException ioe) {
Log.d(TAG, "Can not connect to the URL");
}
return redirectedUrl;
}
注意:当然,所有这些都应该在 AsyncTask 或 Thread 中完成。这将生成可供下载的正确链接
2014 年 7 月 25 日更新:Dropbox 共享 URL 发生变化
预期的 URL 类型提示
来自 Dropbox 团队:
我们想让您提前了解即将对 URL 进行的更改
Dropbox 共享链接的结构。虽然不是 API 的一部分,但
更改可能会影响操纵从
/shares 端点或选择器返回的“预览”链接类型
随叫随到。
返回的链接现在将附加一个 ?dl=0。
例如,而不是
https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx,你会的
接收网址
喜欢这个链接
https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx?dl=0.