简体   繁体   English

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

[英]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. 我目前正在开发一款同步用户Google云端硬盘中某个特定文件夹的应用。 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 1)监视更改提要并查找任何文件更改
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. 2)经常请求整个驱动器中的所有文件,例如。 service.files().list().execute() and look for changes within the specific tree. service.files()。list()。execute()并查找特定树中的更改。 This is a brute force approach. 这是一种蛮力的方法。 It will be too slow if the user has 1000's of files in their drive. 如果用户的驱动器中有1000个文件,则速度太慢。

3) Start at the specific folder, and move down the folder tree looking for changes. 3)从特定文件夹开始,然后向下移动文件夹树以查找更改。 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. 如果特定树中只有少数目录,则此方法会很快,但仍会导致大量API请求。

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. 我是否可以对方法1,2或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. 首先,如果您的应用程序使用的是drive.file范围,那么它只会看到自己的文件。 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. 所以在folder-top / folder-1 / folder-1a / folder-1ai中创建文件时。 you could declare both folder-1ai and folder-top as parents. 您可以将folder-1ai folder-top声明为父项。 Then you simply need to check for folder-top. 然后你只需要检查文件夹顶部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Drive API无法找到任何文件夹 - Google Drive API can not find any folder 如何在 Python 中使用 Google Drive API 创建新文件夹? - How can I create a new folder with Google Drive API in Python? **如何在 Python Google Drive API 中列出多个文件夹的内容? - **How to list the contents of Multiple folder in Python Google Drive API? Google Drive API如何找到文件的路径? - Google Drive API How can I find the path of a file? 如何在 Google Drive API 中按路径查找文件夹 ID? - How to find folder ID by path in Google Drive API? 如何在 python 中使用 pydrive 在谷歌驱动器中查找子文件夹 ID - How to find the sub folder id in google drive using pydrive in python 如何使用 Python 将文件插入/上传到 Google Drive API v3 中的特定文件夹 - How can I insert/upload files to a specific folder in Google Drive API v3 using Python 如何通过 python 中安装的谷歌驱动器上文件的路径获取文件/文件夹的共享链接? - How can I get share link of file/folder by path to the file on insalled google drive in python? 我可以使用 Python 服务帐户创建 Google Drive 文件夹吗? - Can I create a Google Drive folder using service account with Python? 我的谷歌表格文件没有源文件夹,我必须使用 python 将它移动到驱动器文件夹中 - My google sheets file have no source folder , I've to move it into drive folder using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM