查询失败 Google 驱动器 Android

Query fails Google Drive Android

我正在使用此代码:

GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(Drive.API)
                .addScope(Drive.SCOPE_FILE)
                .addScope(Drive.SCOPE_APPFOLDER)
                .build();
Query query = new Query.Builder().addFilter(Filters.and(Filters.and(Filters.and(Filters.eq
                    (SearchableField.TITLE, getString(R.string.app_name)), Filters
                    .eq(SearchableField.TRASHED, false)), Filters.eq(SearchableField.PARENTS, Collections
                    .singletonList(Drive.DriveApi
                    .getRootFolder(client)
                    .getDriveId()))), Filters.eq(SearchableField.MIME_TYPE, GoogleDriveClient.FOLDER_MIME))).build();
            DriveApi.MetadataBufferResult result = Drive.DriveApi.query(client, query).await(TIMEOUT, TimeUnit.SECONDS);
            if (!result.getStatus().isSuccess()) {
                client.disconnect();
                return;
            }

总是报错:Status{statusCode=INTERNAL_ERROR, resolution=null}

我在 Google 控制台中启用了驱动器 Api,我再次检查了我的 SHA1 指纹并且其他操作正常。是否允许执行查询?

这是 Querying for Files

的文档

You can use the com.google.android.gms.drive.query package to search a user's Drive account for files whose metadata match your search criteria. You can issue a query for a specific folder or on the entire filesystem.

Note: The Android Drive API only works with the https://www.googleapis.com/auth/drive.file scope. This means that only files which a user has opened or created with your application can be matched by a query.

这是构建查询的示例。

A query is created by building an instance of the Query class and specifying the search criteria with Filters. The following example finds all files with the title "HelloWorld.java".

Query query = new Query.Builder()
        .addFilter(Filters.eq(SearchableField.TITLE, "HelloWorld.java"))
        .build();

You can use the Filters class to build expressions. Multiple filters can be joined together using the and and or methods.

Once a Query object has been constructed it can be executed on the entire file system using Drive.DriveApi as follows:

Drive.DriveApi.query(googleApiClient, query);

This query starts in the My Drive (the root) folder and recursively traverse the entire filesystem, returning all entries matching the Filters expression tree.

A query can alternatively be executed only in a specific folder using an instance of the DriveFolder class, as shown by:

DriveFolder folder= ...;
folder.query(query);

This call does not scan recursively; only direct entries in this folder matching filter conditions are returned.