How can I find if the contents in a Google Drive folder have changed

I am currently working on an app that syncs one specific folder in a users Google Drive. I need to find when any of the files/folders in that specific folder have changed. The actual syncing process is easy, but I don't want to do a full sync every few seconds. I am condisering one of these methods:

1) Moniter the changes feed and look for any file changes
This method is easy but it will cause a sync if ANY file in the drive changes.

2) Frequently request all files in the whole drive eg. service.files().list().execute() and look for changes within the specific tree. This is a brute force approach. It will be too slow if the user has 1000's of files in their drive.

3) Start at the specific folder, and move down the folder tree looking for changes. This method will be fast if there are only a few directories in the specific tree, but it will still lead to numerous API requests.

Are there any better ways to find whether a specific folder and its contents have changed? Are there any optimisations I could apply to method 1,2 or 3.


As you have correctly stated, you will need to keep (or work out) the file hierarchy for a changed file to know whether a file has changed within a folder tree.

There is no way of knowing directly from the changes feed whether a deeply nested file within a folder has been changed. Sorry.


There are a couple of tricks that might help.

Firstly, if your app is using drive.file scope, then it will only see its own files. Depending on your specific situation, this may equate to your folder hierarchy.

Secondly, files can have multiple parents. So when creating a file in folder-top/folder-1/folder-1a/folder-1ai. you could declare both folder-1ai and folder-top as parents. Then you simply need to check for folder-top.

链接地址: http://www.djcxy.com/p/66430.html

上一篇: api不可能使用createdDate

下一篇: 如何查找Google云端硬盘文件夹中的内容是否已更改