谷歌推动Android API(GDAA)getResourceId()返回null(计时问题) [英] Google Drive Android API (GDAA) getResourceId() returning null (timing issue)

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

问题描述

在测试的删除,垃圾的功能在<一个讨论href="http://stackoverflow.com/questions/22295903/how-to-delete-a-file-on-google-drive-using-google-drive-android-api">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在REST的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();

您获得的值。过了一会儿(随机的,很难确定),如果你重复的查询,最后你会得到你的资源ID。我知道为什么,它可能是一个延迟的问题。我只是征求了谷歌支持团队的评论。有没有一种方法来获得控制权?查询延迟状态?

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.

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

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