Google Drive Android API (GDAA) getResourceId() 返回 null(时间问题) [英] Google Drive Android API (GDAA) getResourceId() returning null (timing issue)

查看:18
本文介绍了Google Drive Android API (GDAA) getResourceId() 返回 null(时间问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在测试 SO 22295903,我遇到了这个问题.

When testing of delete, trash functionality discussed in SO 22295903, I've run into this issue.

1/创建一个包含内容的文件

1/ Create a file with contents

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/使用查询检索文件(它的标题):

2/ retrieve the file using query (it's title):

ArrayList<DriveId> findAll(String title, String mime, DriveFolder fldr) {
  ArrayList<DriveId> dIDs = null;
  if (isConnected()) try {
    ArrayList<Filter> fltrs = new ArrayList<Filter>();
    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<DriveId>();
        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.尝试使用它来获取资源 ID,以便在 RESTful API 或其他地方使用.

3/ You get valid DriveId. Try to use it to gain resource ID to use in RESTful API, or elsewhere.

String fileID = drvId.getResourceId();

你得到一个 null 值.片刻之后(随机,难以指定),如果您重复查询,您最终将获得您的资源 ID.我知道为什么,这可能是延迟问题.我只是征求 Google 支持团队的意见.有没有办法获得控制权?查询延迟状态?

You get a null value. After a few moments (random, difficult to specify), if you repeat the query, you'll finally get your resource ID. I know why, it is probably a latency issue. I'm just soliciting a comment from the Google Support Team. Is there a way to gain control? Query latency status?

推荐答案

发生这种情况是因为更改首先在本地持久化,然后在(可能)稍后我们有足够的网络连接时上传到服务器.不幸的是,在新创建的文件提交到服务器之前,资源 ID 不可用.

This happens because changes are persisted locally first, and then uploaded to the server at a (possibly) later time when we have sufficient network connectivity. Unfortunately the resource id is not available until the newly created file is committed to the server.

目前您所能做的就是等待它可用.我们正在努力添加一些内容,以简化此流程,敬请期待.

Currently all you can do is wait for it to be available. We are working on some additions that will make this flow easier, so stay tuned.

这篇关于Google Drive Android API (GDAA) getResourceId() 返回 null(时间问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆