在测试SO 22295903中讨论的删除,垃圾功能时,我遇到了这个问题.
1 /创建包含内容的文件
GoogleApiClient _gac; DriveFile createFileWait(DriveFolder fldr, String name, String mime, byte[] buff) { DriveFile drvFile = null; try { ContentsResult rslt = Drive.DriveApi.newContents(_gac).await(); if (rslt.getStatus().isSuccess()) { Contents cont = rslt.getContents(); cont.getOutputStream().write(buff); MetadataChangeSet meta = (mime == null) ? new MetadataChangeSet.Builder().setTitle(name).build() : new MetadataChangeSet.Builder().setTitle(name).setMimeType(mime).build(); drvFile = fldr.createFile(_gac, meta, cont).await().getDriveFile(); } } catch (Exception e) {} return drvFile; }
2 /使用查询检索文件(它的标题):
ArrayListfindAll(String title, String mime, DriveFolder fldr) { ArrayList dIDs = null; if (isConnected()) try { ArrayList fltrs = new ArrayList (); fltrs.add(Filters.eq(SearchableField.TRASHED, false)); if (title != null) fltrs.add(Filters.eq(SearchableField.TITLE, title)); if (mime != null) fltrs.add(Filters.eq(SearchableField.MIME_TYPE, mime)); Query qry = new Query.Builder().addFilter(Filters.and(fltrs)).build(); MetadataBufferResult rslt = (fldr == null) ? Drive.DriveApi.query(_gac, qry).await() : fldr.queryChildren(_gac, qry).await(); if (rslt.getStatus().isSuccess()) { MetadataBuffer mdb = null; try { mdb = rslt.getMetadataBuffer(); if (mdb == null) return null; dIDs = new ArrayList (); for (Metadata md : mdb) { if ((md == null) || md.isTrashed()) continue; dIDs.add(md.getDriveId()); } } finally { if (mdb != null) mdb.close(); } } } catch (Exception e) {} return dIDs; }
3 /您获得有效的DriveId.尝试使用它来获取在RESTful API或其他地方使用的资源ID.
String fileID = drvId.getResourceId();
你得到一个空值.片刻之后(随机,难以指定),如果您重复查询,您将最终获得您的资源ID.我知道为什么,这可能是一个延迟问题.我只是征求谷歌支持团队的评论.有办法获得控制权吗?查询延迟状态?