android - Dropbox 共享文件 URL

标签 android share dropbox

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

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

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

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

最佳答案

根据此处提到的 DropBox 所做的更改:https://www.dropbox.com/help/16/en 将不再有公共(public)文件夹,而是可以通过共享链接访问文件。

如果您使用 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/07/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;
}

Note: All of this should be done of course in AsyncTask or Thread. This will produce proper links ready to download

2014/07/25 更新:Dropbox 共享 URL 的变化
关于预期 URL 类型的注意事项
来自 Dropbox 团队:

We wanted to give you a heads up about an upcoming change to the URL structure of Dropbox shared links. While not part of the API, the change could affect apps that manipulate the URLs returned from the /shares endpoint or the "preview" link type returned by the Chooser Drop-in.

Links returned will now have a ?dl=0 appended to them.

E.g., instead of https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx, you'll receive URLs like this link https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx?dl=0.

关于android - Dropbox 共享文件 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5765533/

相关文章:

android - 如何在android中为多个设备和版本开发应用程序

java - 如何在命令行 Java 中实现 Dropbox OAuth?

python - 我如何在 PythonAnywhere 上而不是从 Dropbox 共享文件夹部署 web2py?

android - 使用 LayoutParams 将自定义 View 在relativelayout中居中

java - 后台和前台执行服务

android - 使用 Intent 在 Android 应用程序中共享图像将其作为文本文件而不是照片发送

android - 具有后台处理功能的 ShareActionProvider

android - 使用 Picasso 的 ShareActionProvider 分享图像

unix - 通过wget从Dropbox链接下载包含子文件夹的文件夹到Unix服务器

android - Eclipse无法连接花括号