google-app-engine - Google Drive API - 太慢了。

标签 google-app-engine google-api google-drive-api google-api-java-client google-drive-realtime-api

我刚刚开始研究 Google Drive API。我有一个问题,它太慢了。我使用文档中的方法。例如:

List<File> getFilesByParrentId(String Id, Drive service) throws IOException {

    Children.List request = service.children().list(Id);
    ChildList children = request.execute();

    List<ChildReference> childList = children.getItems();
    File file;

    List<File> files = new ArrayList<File>();
    for (ChildReference child : childList) {
        file = getFilebyId(child.getId(), service);

        if (file == null) {
            continue;
        } else if (file.getMimeType().equals(FOLDER_IDENTIFIER)) {
            System.out.println(file.getTitle() + " AND "
                    + file.getMimeType());
            files.add(file);
        }
    }

    return files;
}

private File getFilebyId(String fileId, Drive service) throws IOException {
    File file = service.files().get(fileId).execute();
    if (file.getExplicitlyTrashed() == null) {
        return file;
    }
    return null;
}

问题:该方法有效,但速度太慢,需要大约 30 秒。

我该如何优化它?例如,不获取所有文件(仅文件夹,或仅文件)。或类似的东西。

最佳答案

你可以使用 q 参数和一些类似的东西:

service.files().list().setQ(mimeType != 'application/vnd.google-apps.folder and 'Id' in parents and trashed=false").execute();

这将为您提供所有不是文件夹、未被删除且其父级具有 id 的文件。全部在一个请求中。

顺便说一句,API 并不慢。您的算法提出了太多请求。

关于google-app-engine - Google Drive API - 太慢了。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19159364/

相关文章:

python - GAE NDB 结构化列表到 Json

google-api - 如何通过 google/apiclient 从 PHP 使用 Google Drive API 的 API key

google-api - 将 Google Cloud Storage 中的文件添加到云端硬盘

google-drive-api - Google 云端硬盘和 Chrome 网上应用店身份验证

android - Google Drive Api 账户授权

google-apps-script - 如何将链接转换为文件名?

google-app-engine - 谷歌应用引擎 : Endpoints authentication when custom auth or Open ID is used

reactjs - [next-auth][错误][CLIENT_FETCH_ERROR] Google App Engine 上的下一个身份验证错误

java - Google App Engine - 生成二维码

google-sheets - Google Sheet API 中从未设置 TextRotation 角度