Dropbox共享文件URL

Ija*_*med 10 android share dropbox

我正在开发一个Android应用程序,它使用Dropbox来组织文件.我正在探索Dropbox API,但其描述和帮助有限,因为没有Dropbox API的文档.

我仍然希望将文件管理为某些功能,例如放置文件并从Dropbox获取文件.现在的问题是当我在Dropbox 公共文件夹中放入一些文件时,我需要一个URL来共享应用程序中的联系人.但是在API中我找不到任何返回要共享的文件的Web URL的函数(就像在Dropbox的Deskotop界面中,用户可以获得共享URL发送给朋友).

有人可以帮我弄清楚如何与应用程序中的联系人共享该文件?

或者使用Dropbox Android API共享文件的任何其他方式?

MP2*_*P23 13

根据在这里提到的DropBox所做的更改:https://www.dropbox.com/help/16/en 将不再有公共文件夹,而是可以通过Share Link完成对文件的访问.

如果您使用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);
}   
}
Run Code Online (Sandbox Code Playgroud)

更新:2014/07/20作者:Dheeraj Bhaskar 使用以下辅助函数以及上述函数.由于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;
}
Run Code Online (Sandbox Code Playgroud)

注意:所有这些当然应该在AsyncTask或Thread中完成.这将生成准备下载的正确链接

更新2014/07/25:Dropbox共享URL的更改
提前了解Dropbox团队所需的URL类型
:

我们想让您了解即将对Dropbox共享链接的URL结构进行的更改.虽然不是API的一部分,但更改可能会影响操作从/ shares端点返回的URL的应用程序或Chooser Drop-in返回的"预览"链接类型.

返回的链接现在会附加一个?dl = 0.

例如,而不是 https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx,您会收到类似这样的链接网址 https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx?dl= 0.