从没有身份验证的 Dropbox 链接获取元数据 [英] Get Metadata from Dropbox Link Without Auth

查看:26
本文介绍了从没有身份验证的 Dropbox 链接获取元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 Dropbox 上的共享链接检查版本更改/获取文本文件的元数据.我不会使用 dropbox api,因为它让用户使用自己的帐户.我希望他们链接到我的帐户,但我不能手动这样做,因为我以后可能会更改我的密码.

I want to check for a version changed/get metadata of a text-file with a shared link on dropbox. I will not be using dropbox api as it makes users use their own accounts. I want them to link to my account and I cannot do that manually since I might change my password later.

所以:没有身份验证令牌,只需从保管箱的共享链接获取元数据,以便我可以检查版本更改,如果版本已更改,请下载新文件的内容.

so: no auth token, just get metadata from shared link of dropbox so that I can check for version changes and if the version has changed download the contents of the new file.

另外:我愿意接受其他建议以使这项工作也有效.请详细说明您的解决方案.

also: I'm open to other suggestions to make this work as well. Please explain in a little detail your solution.

更新的电子标签问题:

public void getFromOnlineTxtDatabase(){
        try{
            URL url = new URL("url-here");
            HttpURLConnection.setFollowRedirects(true);
            HttpURLConnection con = (HttpURLConnection) url.openConnection();
            con.setDoOutput(false);
            con.setReadTimeout(20000);
            con.setRequestProperty("Connection", "keep-alive");
            //get etag for update check
                String etag = con.getHeaderField("etag");
            //String etag= "";

            con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
            ((HttpURLConnection) con).setRequestMethod("GET");
            //System.out.println(con.getContentLength()) ;
            con.setConnectTimeout(5000);
            BufferedInputStream in = new BufferedInputStream(con.getInputStream());
            int responseCode = con.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println(responseCode);
            }
            StringBuffer buffer = new StringBuffer();
            int chars_read;
            //int total = 0;
            while ((chars_read = in.read()) != -1) 
            {
                char g = (char) chars_read;
                buffer.append(g);
            }
            final String page = buffer.toString();
            //create password_ems.txt to internal
            if (fileExistance("data.txt")){
                File dir = getFilesDir();
                File file = new File(dir, "data.txt");
                boolean deleted = file.delete();
                stringToTxt(page, "data.txt");


            }else{
                stringToTxt(page, "data.txt");
            }

            if (fileExistance("data_etag.txt")){
                File dir = getFilesDir();
                File file = new File(dir, "etag.txt");
                boolean deleted = file.delete();
                stringToTxt(etag, "etag.txt");


            }else{
                //create etag_file
                stringToTxt(etag, "data_etag.txt");
            }

            //  Log.i("Page", page);
        }catch(Exception e){
            showDialog("Database Fetch Failure","Unable to Fetch Password Database, check your internet" +
                    " connection and try again later.",0);
            Log.i("Page", "Error");
        }

    }

推荐答案

如果您对公共或共享的 Dropbox URL 执行 HTTP HEAD 请求,除其他外,您将获得一个 etag 标头.我不知道这种行为是否得到保证,因为我认为它没有记录在任何地方,但至少现在 etag 标头可用于确定文件何时更改.(如果 etag 不同,则文件已更改.)

If you do an HTTP HEAD request against a public or shared Dropbox URL, you'll get, among other things, an etag header. I don't know that this behavior is guaranteed, since I don't think it's documented anywhere, but at least for now the etag header can be used to determine when a file has changed. (If the etag is different, the file has changed.)

编辑

通常在使用 ETags 时,最有效的做法是发出一个 GET 请求,其标头为 If-None-Match: <old etag>.如果内容没有改变,这将响应一个 304,但如果内容改变了,这将按照正常的 GET 请求下载新的内容(响应将是 200).

In general when using ETags, the most efficient thing to do is issue a GET request with a header of If-None-Match: <old etag>. If the content hasn't changed, this will respond with a 304, but if the content has changed, this will download the new content as per a normal GET request (and the response will be 200).

这篇关于从没有身份验证的 Dropbox 链接获取元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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