Dropbox的共享文件的URL [英] Dropbox Sharing file URL

查看:372
本文介绍了Dropbox的共享文件的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我还是想来管理这些文件的一些功能,比如把一个文件并获得从Dropbox的文件。现在的问题是,当我把一些文件的Dropbox的公开的文件夹,我需要一个URL分享给我的应用程序中的联系人。但是,在API中我找不到返回该文件的网页的URL分享任何功能(就像在Dropbox的的Deskotop接口,用户可以得到一个共享的网址发送给朋友)。

有人能帮助我弄清楚如何在应用程序的联系人共享文件?

或者使用Dropbox的Andr​​oid的API,任何其他的方式来共享文件?

解决方案

据作出DropBox的文件档案化管理的变化在这里:的 https://www.dropbox.com/help/16/en 不会有更多的公共文件夹,而不是对文件的访问可以通过分享链接来完成。

如果您使用的Andr​​oid DropBox的核心API,然后共享链路可以检索这种方式:

  //获取元数据目录
项的dirent = mApi.metadata(的mpath,1000,空,真,空);

对于(输入ENT:dirent.contents){

字符串shareAddress = NULL;
如果(!ent.isDir){
    DropboxLink shareLink = mApi.share(ent.path);
    shareAddress = getShareURL(shareLink.url).replaceFirst(https://开头WWW,https://开头DL);
    Log.d(TAG,Dropbox的共享链接+ shareAddress);
}
}
 

更新:二○一四年七月二十〇日由Dheeraj巴斯卡尔 使用下面的辅助函数非常久远上述功能。 由于DropBox的开始发送短链接是多一点的问题得到适当的链接。 现在,我使用这个方法:

我们只需装入URL,跟随重定向,并获得新的URL。

 字符串getShareURL(字符串strURL){
    URLConnection的康恩= NULL;
    字符串redirectedUrl = NULL;
    尝试 {
        URL inputURL =新的URL(strURL);
        康恩= inputURL.openConnection();
        conn.connect();

        InputStream的是= conn.getInputStream();
        的System.out.println(重定向的URL:+ conn.getURL());
        redirectedUrl = conn.getURL()的toString()。
        is.close();

    }赶上(MalformedURLException异常E){
        Log.d(TAG,请输入一个有效的URL);
    }赶上(IOException异常IOE){
        Log.d(TAG,无法连接到URL);
    }

    返回redirectedUrl;
}
 

  

注意:所有这一切都应该在AsyncTask的或线程中完成的课程。这将产生正确的链接就可以下载

更新2014年7月25日:变化Dropbox的份额网址
在那种网址的抬头期待
从Dropbox的球队:

  

我们想给你一个头了关于即将到来的变化网址   Dropbox的结构共享链接。尽管API不是一部分,   变化可能会影响操纵从返回的URL的应用程序   /股端点或选配返回的preVIEW链接类型   插入式

     

返回链接现在将有一个?DL = 0附加给他们。

     

而不是如,    https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx ,你会   收到的网址   像这样的链接    https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx ?DL = 0

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?

解决方案

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.

这篇关于Dropbox的共享文件的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆