Google Drive Android API - 无效的 DriveId 和 Null Resourc

时间:2023-03-19
本文介绍了Google Drive Android API - 无效的 DriveId 和 Null ResourceId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我整天都在与这段代码作斗争,但没有运气.我从以下代码开始 示例来自 Google.

I have been battling this code the whole day without luck. I started by following this code sample from Google.

问题是该文件夹已成功创建,但在 onResult() 内,我总是得到一个无效或不完整的 DriveId 或 resourceId.这意味着我无法在我创建的文件夹中创建文件.这是我正在使用的代码:

The problem is that the folder gets created successfully but inside onResult(), I always get a DriveId or resourceId that is invalid or incomplete. That means I cannot create a file inside the folder I created. Here is the code I am using:

public class CreateFolderActivity extends BaseDemoActivity {

@Override
public void onConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);
    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
            .setTitle("MyAppFolder").build();
    Drive.DriveApi.getRootFolder(getGoogleApiClient()).createFolder(
            getGoogleApiClient(), changeSet).setResultCallback(callback);
}

final ResultCallback<DriveFolderResult> callback = new ResultCallback<DriveFolderResult>() {
    @Override
    public void onResult(DriveFolderResult result) {
        if (!result.getStatus().isSuccess()) {
            showMessage("Error while trying to create the folder");
            return;
        }

        // this value is always invalid with ending == operators
        Log.d("DRIVEID", "Created a folder: " + result.getDriveFolder().getDriveId());
    }
  };
}

每当我运行此代码时,我都会得到以下看起来不完整的 id:

Whenever I run this code, I get the following id which appears incomplete:

CAESABi2VyCCzdWOuVMoAQ==

我不知道这里发生了什么!

I don't know what is happening here!

我在 Google 上搜索并阅读了添加侦听器以侦听完成事件,但它们似乎都不起作用.

I have Google'd around and read of adding listeners to listen for completion events but none of them seem to work.

我在 SO 上看到了几乎类似的问题,但没有一个对我有用.

I have seen nearly similar questions on SO on this but none of them work for me.

我在应用创建后通过浏览器手动复制了 FolderId,然后粘贴到我的 android 代码中,应用成功创建了一个文件.但这不是事情应该如何运作的方式.

I manually copied the FolderId through my browser after the app created it and then pasted to my android code and the app created a file successfully. But this is not how things should work.

我想等待同步完成吗?如果是,如何?

Am I suppose to wait for the sync to complete and if so, how?

提前谢谢你!

推荐答案

你的问题大概可以找到答案 这里.你得到的 DriveId 没问题,但你不应该直接处理它.它是一个'初步' DriveId,在提交对象后会发生变化(再次,请参阅 SO 22874657).您可以比较您获得的 DriveId 与您将在onCompletion(CompletionEvent 事件)"中获得的 DriveId 来测试它.

The answer to your problem can probably be found here. The DriveId you're getting is OK, but you should not handle it directly. It is a 'preliminary' DriveId that changes after the object has been committed (again, see SO 22874657). You can test it comparing DriveId you're getting vs. DriveId you'll get in 'onCompletion(CompletionEvent event)'.

这只是 GDAA 逻辑的副作用之一,可以保护您免受在线/离线网络状态的影响,从而导致无法预测的延迟.你只需要依赖回调.

This is just one of the side effects of GDAA's logic, shielding you from on-line / off-line network state resulting in unpredictable delays. You just have to rely on callbacks.

但令我惊讶的是,您不能立即将此初步"DriveId(如果是文件夹)用作另一个对象(文件夹/文件)的父级.我从未经历过,立即将初步"DriveId 传递给另一个 GDAA 方法.
在 ResourceId 的情况下是不同的.那个在 GDAA 中是次要的,仅在您离开设备时使用.在提交(上传)对象之前,GDAA 并不知道.

But I am surprised that you can't use this 'preliminary' DriveId (in case of a folder) immediately as a parent of another object (folder/file). I have never experienced it, passing the 'preliminary' DriveId immediately to another GDAA method.
It is different in case of the ResourceId. That one is secondary in the GDAA and is used only if you go outside of the device. It is not known to the GDAA until the object is committed (uploaded).

我在这个 demo 中使用了类似的逻辑(创建文件夹/文件树)(参见 MainActivity.createTree() 方法).欢迎您挖掘它.

I used similar logic (creating folder / file tree) in this demo (see MainActivity.createTree() method). You're welcome to dig in it.

中讨论了一个相关问题SO 34318220.

祝你好运

这篇关于Google Drive Android API - 无效的 DriveId 和 Null ResourceId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:谷歌驱动api服务账户查看上传文件到谷歌驱动使 下一篇:使用 Google Drive SDK 将文件保存在特定文件夹中

相关文章

最新文章