[英]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.因此,请按如下方式修改您的端点并再次测试。
String sUrl = "https://www.googleapis.com/drive/v3/files?q=%271RpFcoEWYsRt2MX7FotKcLICqYq6l5MFY%27+in+parents&key=myKey";
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
已添加到端点。pageToken
.如果文件数超过 1000,您可以使用pageToken
检索所有文件列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.