Filters.ownedByMe不适用于Android的Drive API和#39; (但在适用于Java的API客户端库中正常工作')

时间:2016-01-10 13:26:43

标签: java android google-drive-api google-drive-android-api

以前,我正在使用" API客户端库for Java"在appdata文件夹中执行文件搜索。

在API Client Library for Java中搜索代码

private static void searchFromGoogleDrive(Drive drive, String qString) {
    try {
        Files.List request = drive.files().list().setQ(qString);

        do {                
            FileList fileList = request.execute();

            for (com.google.api.services.drive.model.File f : fileList.getItems()) {

                final String title = f.getTitle();

                if (title == null || f.getDownloadUrl() == null || f.getDownloadUrl().length() <= 0) {
                    continue;
                }
                ...
            }

            request.setPageToken(fileList.getNextPageToken());
        } while (request.getPageToken() != null && request.getPageToken().length() > 0);
    } catch (IOException ex) {
        log.error(null, ex);
        return;
    }
    return;
}

它对以下查询字符串完全正常。

title contains 'jstock-fe78440e-e0fe-4efb' and trashed = false and 'appdata' in parents and 'me' in owners

最近,我尝试迁移代码以使用&#34; Drive API for Android&#34;。我有GoogleApiClient

的两个范围
  • Drive.SCOPE_FILE
  • Drive.SCOPE_APPFOLDER

在Android版Drive API中搜索代码

private static void searchFromGoogleDrive(GoogleApiClient googleApiClient) {
    DriveFolder driveFolder = Drive.DriveApi.getAppFolder(googleApiClient);

    Query query = new Query.Builder()
            .addFilter(Filters.and(
                Filters.contains(SearchableField.TITLE, "jstock-fe78440e-e0fe-4efb"),
                Filters.eq(SearchableField.TRASHED, false),
                Filters.ownedByMe()
            ))
            .build();

    DriveApi.MetadataBufferResult metadataBufferResult = driveFolder.queryChildren(googleApiClient, query).await();

    if (metadataBufferResult == null) {
        Log.i("CHEOK", "metadataBufferResult is null");
    } else {
        Log.i("CHEOK", "metadataBufferResult's status = " + metadataBufferResult.getStatus().isSuccess());
    }

    if (metadataBufferResult != null && metadataBufferResult.getStatus().isSuccess()) {
        MetadataBuffer metadataBuffer = null;
        try {
            metadataBuffer = metadataBufferResult.getMetadataBuffer();
            if (metadataBuffer != null ) {
                for (Metadata md : metadataBuffer) {
                    if (md == null || !md.isDataValid()) {
                        continue;
                    }

                    Log.i("CHEOK", "title = " + md.getTitle());
                }   // for
            }   // if
        } finally {
            if (metadataBuffer != null) {
                metadataBuffer.release();
            }
        }
    }

    return;
}

我意识到,Filters.ownedByMe是造成问题的原因。

以下是基于不同查询的不同结果。

失败

Query query = new Query.Builder()
        .addFilter(Filters.and(
            Filters.contains(SearchableField.TITLE, "jstock-fe78440e-e0fe-4efb"),
            Filters.eq(SearchableField.TRASHED, false),
            Filters.ownedByMe()
        ))
        .build();            
// metadataBufferResult's status = false

失败

Query query = new Query.Builder()
        .addFilter(Filters.and(
            Filters.ownedByMe()
        ))
        .build();
// metadataBufferResult's status = false

成功

Query query = new Query.Builder()
        .addFilter(Filters.and(
            Filters.contains(SearchableField.TITLE, "jstock-fe78440e-e0fe-4efb"),
            Filters.eq(SearchableField.TRASHED, false)
        ))
        .build();    
// metadataBufferResult's status = true
// title = jstock-fe78440e-e0fe-4efb-881d-264a01be483c-checksum=2298926779-date=1452429908167-version=1107.zip

似乎Filters.ownedByMe()在适用于Android的云端硬盘API中无法正常工作

有什么我可以纠正的吗?

0 个答案:

没有答案