在 Google 驱动器上删除的文件夹不会反映在 Play 服务驱动器 API 中
Folder deleted on Google Drive doesn't reflect in Play Services Drive API
我一直在努力弄清楚我做错了什么,或者这是否是预期的行为。我正在创建一个使用 Google Play 服务驱动器 API 将文件上传到 Google 驱动器的应用程序。在我创建父文件夹之前,我检查该文件夹是否已经存在。为了进行测试,我删除了该文件夹,然后签入该应用程序,但该应用程序始终检测到该文件夹仍然存在。
我检查了 MetaDataBuffer 上的 isTrashed,它总是报告为 false。
这是应用程序和驱动器服务器之间的同步问题吗?
这是我使用的查询:
new Query.Builder().addFilter(
Filters.and(
Filters.eq(SearchableField.TRASHED, false),
Filters.eq(SearchableField.MIME_TYPE, MIME_TYPE_FOLDER),
Filters.eq(SearchableField.TITLE, name)
)).build();
欢迎来到俱乐部 :-)。此问题是 GDAA discussed all over the place. What you see is the side-effect of having a 'buffering' layer between your app and GooDrive. When placing any GDAA related request, you're talking to GooPlaySvcs layer, that has no clue what other apps (http://drive.google.com) 对驱动器所做的已知怪癖(原谅,功能)之一。可能会发生很多奇怪的事情,例如:
1/ 使用您的应用程序创建一个文件夹
2/ 垃圾桶和使用http://drive.google.com
永久删除那个文件夹
3/ 让您的应用程序在该文件夹中创建一个文件 - 没有失败的迹象,文件是在 Google never-never-land
某处的文件夹中创建的
如果你真的需要知道当前的驱动器状态,你必须使用 REST Api 轮询驱动器。
另一种控制它的方法是将您的 folder/files 写入应用文件夹,使其他应用无法访问它们。然后,即使你不能删除一个文件'from behind'。不过要小心,有一个相关的 problem/issue 与您可以在测试时 运行 进入的应用程序文件夹。
祝你好运
正如 Sean 所提到的,GDAA 有一个缓存层,可能会导致您的应用获得过时的查询结果。
在查询之前确保缓存是最新的方法是调用 DriveApi#requestSync。
缓存层允许您的应用程序在离线时运行。如果设备处于离线状态,Drive API 将在设备重新在线时上传您的文件。
REST API 确实更直接,如果您不关心离线情况或乐于在您的应用程序中处理它,它可能是一个不错的选择。
希望这有帮助。
这个问题有点老,但答案可能对遇到完全相同问题的其他人有用。
在进行任何需要最新 metadataBuffer
的查询/操作之前,您必须调用 DriveClient.requestSync()
来更新它。
但使用此方法时要小心。根据以下文档:
public abstract Task<Void> requestSync ()
Requests synchronization
with the server to download any metadata changes that have occurred
since the last sync with the server.
Typically, this method should be called when the user requests a
refresh of their list of files. Once this method returns, performing a
query will return fresh results.
In order to avoid excessive load on the device and server, sync
requests are rate-limited. If the request has been rate-limited, the
operation will fail with the DRIVE_RATE_LIMIT_EXCEEDED status. This
indicates that a sync has already occurred recently so there is no
need for another. After a sufficient backoff duration, the operation
will succeed when re-attempted.
Source: Google APIs for Android.
我的实现如下:
private void refreshMetadata(final File databaseFile) {
mDriveClient.requestSync()
.addOnSuccessListener(aVoid -> checkIfBackupFolderIsInDrive(databaseFile))
.addOnFailureListener(e -> Utils.log("SettingsFragment", "Could not update metadata buffer: " + e.getMessage()));
}
我请求同步。如果成功,我将开始我想做的操作。如果现在失败,我只会记录事件。
我一直在努力弄清楚我做错了什么,或者这是否是预期的行为。我正在创建一个使用 Google Play 服务驱动器 API 将文件上传到 Google 驱动器的应用程序。在我创建父文件夹之前,我检查该文件夹是否已经存在。为了进行测试,我删除了该文件夹,然后签入该应用程序,但该应用程序始终检测到该文件夹仍然存在。
我检查了 MetaDataBuffer 上的 isTrashed,它总是报告为 false。
这是应用程序和驱动器服务器之间的同步问题吗?
这是我使用的查询:
new Query.Builder().addFilter(
Filters.and(
Filters.eq(SearchableField.TRASHED, false),
Filters.eq(SearchableField.MIME_TYPE, MIME_TYPE_FOLDER),
Filters.eq(SearchableField.TITLE, name)
)).build();
欢迎来到俱乐部 :-)。此问题是 GDAA discussed all over the place. What you see is the side-effect of having a 'buffering' layer between your app and GooDrive. When placing any GDAA related request, you're talking to GooPlaySvcs layer, that has no clue what other apps (http://drive.google.com) 对驱动器所做的已知怪癖(原谅,功能)之一。可能会发生很多奇怪的事情,例如:
1/ 使用您的应用程序创建一个文件夹
2/ 垃圾桶和使用http://drive.google.com
永久删除那个文件夹
3/ 让您的应用程序在该文件夹中创建一个文件 - 没有失败的迹象,文件是在 Google never-never-land
如果你真的需要知道当前的驱动器状态,你必须使用 REST Api 轮询驱动器。
另一种控制它的方法是将您的 folder/files 写入应用文件夹,使其他应用无法访问它们。然后,即使你不能删除一个文件'from behind'。不过要小心,有一个相关的 problem/issue 与您可以在测试时 运行 进入的应用程序文件夹。
祝你好运
正如 Sean 所提到的,GDAA 有一个缓存层,可能会导致您的应用获得过时的查询结果。 在查询之前确保缓存是最新的方法是调用 DriveApi#requestSync。 缓存层允许您的应用程序在离线时运行。如果设备处于离线状态,Drive API 将在设备重新在线时上传您的文件。 REST API 确实更直接,如果您不关心离线情况或乐于在您的应用程序中处理它,它可能是一个不错的选择。 希望这有帮助。
这个问题有点老,但答案可能对遇到完全相同问题的其他人有用。
在进行任何需要最新 metadataBuffer
的查询/操作之前,您必须调用 DriveClient.requestSync()
来更新它。
但使用此方法时要小心。根据以下文档:
public abstract Task<Void> requestSync ()
Requests synchronization with the server to download any metadata changes that have occurred since the last sync with the server.
Typically, this method should be called when the user requests a refresh of their list of files. Once this method returns, performing a query will return fresh results.
In order to avoid excessive load on the device and server, sync requests are rate-limited. If the request has been rate-limited, the operation will fail with the DRIVE_RATE_LIMIT_EXCEEDED status. This indicates that a sync has already occurred recently so there is no need for another. After a sufficient backoff duration, the operation will succeed when re-attempted.
Source: Google APIs for Android.
我的实现如下:
private void refreshMetadata(final File databaseFile) {
mDriveClient.requestSync()
.addOnSuccessListener(aVoid -> checkIfBackupFolderIsInDrive(databaseFile))
.addOnFailureListener(e -> Utils.log("SettingsFragment", "Could not update metadata buffer: " + e.getMessage()));
}
我请求同步。如果成功,我将开始我想做的操作。如果现在失败,我只会记录事件。