简体   繁体   English

Google Drive 未显示目录中的所有文件

[英]Google Drive not showing all files in a directory

I'm new to JSON stuff and could not figure out why I'm having this issue, so here I am.我是 JSON 的新手,无法弄清楚为什么我会遇到这个问题,所以我来了。 I have a google drive folder that is publicly shared ( https://drive.google.com/drive/folders/1RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY ).我有一个公开共享的谷歌驱动器文件夹( https://drive.google.com/drive/folders/1RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY )。 Here's the code I use to get entries (it's for testing atm):这是我用来获取条目的代码(用于测试 atm):

new Thread(() -> {
        String sUrl = "https://www.googleapis.com/drive/v3/files?q=%271RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY%27+in+parents&key=myKey";

        try {
            URL url = new URL(sUrl);
            URLConnection urlConnection = url.openConnection();
            urlConnection.connect();

            JsonParser jp = new JsonParser();
            JsonElement root = jp.parse(new InputStreamReader((InputStream) urlConnection.getContent()));
            JsonObject rootObj = root.getAsJsonObject();
            JsonArray files = rootObj.get("files").getAsJsonArray();

            for (JsonElement file : files) {
                String n = file.getAsJsonObject().get("name").getAsString();
                Log.e("amt", counter.getAndIncrement() + "");
                //if (n.toLowerCase().contains(name.toLowerCase())) ret.add(n);
            }

            ((HttpsURLConnection) urlConnection).disconnect();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }).start();

This code prints the numbers 0-99 in the console, always stopping at 99, despite the folder having more files than that.此代码在控制台中打印数字 0-99,始终在 99 处停止,尽管文件夹中的文件多于此。 If anyone has a clue as to why this is happening, please let me know.如果有人知道为什么会发生这种情况,请告诉我。 Alternative methods are welcome as wel!也欢迎其他方法!

In your situation, how about using pageSize to the query parameter?在您的情况下,如何将pageSize用于查询参数? The default value of pageSize is 100 . pageSize的默认值为100 I thought that your issue might be due to this default value.我认为您的问题可能是由于此默认值造成的。 So please modify your endpoint as follows and test it again.因此,请按如下方式修改您的端点并再次测试。

From:从:

String sUrl = "https://www.googleapis.com/drive/v3/files?q=%271RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY%27+in+parents&key=myKey";

To:到:

String sUrl = "https://www.googleapis.com/drive/v3/files?pageSize=1000&q=%271RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY%27+in+parents&key=myKey";
  • pageSize=1000 was added to the endpoint. pageSize=1000已添加到端点。

Note:笔记:

  • If the number of files is over 1000, you can retrieve all file list using pageToken .如果文件数超过 1000,您可以使用pageToken检索所有文件列表。

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将本地目录中的所有文件上传到 Google Drive (Google Drive API V3) - Uploading All Files from local directory to Google Drive (Google Drive API V3) 无法使用Google Drive API获取所有文件的列表 - Unable to get list of all files using google drive API 从Java代码访问Google Drive和Dropbox并执行ls(列表文件)和cd(更改目录)类型的操作 - Acessing Google Drive and Dropbox from java code and performing ls(list files) and cd (change directory) type operation 将多个文件上传到Google云端硬盘? - Uploading multiple files to Google Drive? 从Google云端硬盘下载文件 - Downloading files from google drive Google Guava迭代从Begin目录开始的所有文件 - Google Guava Iterate All Files Starting From a Begin Directory 从Google App Engine应用程序内部读取目录中的所有文件 - Read all files in a directory from inside Google App Engine app 请求所有文件时如何避免读取超时? (谷歌驱动器API) - How to avoid read timeout when requesting all files? (google drive api) zip条目,显示目录为文件 - zip entry showing directory as files ? 如何在不使用 stream 的情况下列出目录或驱动器中的所有文件并仅使用 java 中的 nio api 按创建日期对其进行排序 - ? How can I list all files in directory or drive without using stream and sort it by creation date using just nio api in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM