Dropbox 共享文件 URL

发布于 2024-11-02 21:33:02 字数 375 浏览 3 评论 0原文

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

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

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

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

I am developing an application for Android and which uses Dropbox for organizing the files. I am exploring the Dropbox API but its description and help is limited, as there is no documentation for the Dropbox API.

I still would like to manage the files to some functionality, for example placing a file and getting a file from Dropbox. Now the problem is when I put some files in Dropbox public folder and I need a URL to share to my contacts in the application. But in the API I could not find any function that returns the web URL of the file to share (Just like in the Deskotop interface of Dropbox, a user can get a Shared URL to send to friends).

Could someone help me figure out how to share that file with contacts in the Application?

Or any other way to share a file using Dropbox Android API?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森罗 2024-11-09 21:33:02

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

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

更新:2014/07/20 by 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;
}

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

2014/07/25 更新:Dropbox 共享 URL 的更改
关于预期 URL 类型的提示
来自 Dropbox 团队:

我们想提醒您即将发生的网址变更
Dropbox 共享链接的结构。虽然不是 API 的一部分,
更改可能会影响操纵从返回的 URL 的应用程序
/shares 端点或选择器返回的“预览”链接类型
顺便加入。

返回的链接现在将附加一个 ?dl=0。

例如,代替
https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx ,你会
接收网址
喜欢这个链接
https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx ?dl=0

According to changes made on DropBox metioned here: https://www.dropbox.com/help/16/en
There would be no more Public folders, instead access to files can be done via Share Link.

If you use Android DropBox Core Api then shared link can be retrieved this way:

// 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);
}   
}

UPDATE: 2014/07/20 by Dheeraj Bhaskar
Use the following helper function alongwith the above function.
Since DropBox started to send shortened links it is little bit more problematic to get proper link.
For now, I am using this method :

We simply load the URL, follow the redirects and get the new 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

Update 2014/07/25: Change in dropbox share URLs
A heads-up on the kind of URLs to expect
From the Dropbox team:

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.

柠檬心 2024-11-09 21:33:02

Dropbox 论坛中的一个有用帖子:

http://forums .dropbox.com/topic.php?id=37700&replies=7#post-326432

如果文件的公共链接始终存在

dl.dropbox.com/u/<your users uid>/<path under /Public>/filename

,那么我们可以只需使用 API 来获取并在代码中构建公共 URL 即可。

也许这也可能有帮助:将文件上传到 Dropbox 并复制公共地址。此脚本将文件上传到您的 /Public 目录并使用您的帐户
用于构建其公共 URL 的 UID。然后,它将 URL 回显到控制台。

https://github.com/sylvainfilteau/dropbox-api-command/commit/6aa817c79220c5de4ff5339cd01ea8b528bcac36

我还没有实现 Dropbox 界面,但这是我需要的功能之一发展。我希望一两天内会有更多。

A useful thread in the Dropbox forums:

http://forums.dropbox.com/topic.php?id=37700&replies=7#post-326432

IF The public link for a file is always

dl.dropbox.com/u/<your users uid>/<path under /Public>/filename

then we can just use the API to get and build the public URL in the code.

Perhaps this may also help: Upload a file to Dropbox and copy public address. This script upload a file to your /Public directory and use your accound
UID to build it's public URL. Then, it echoes the URL to the console.

https://github.com/sylvainfilteau/dropbox-api-command/commit/6aa817c79220c5de4ff5339cd01ea8b528bcac36

I am not there yet in my Dropbox interface implementation, but this is one of the functions I need to develop. More in one or two days I hope.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文