Google Drive SDK Push Notifications - watch changes on all files?

天涯浪子 提交于 2019-12-04 08:37:17

问题


The recently launched Push Notifications service is very cool and looks as a big improvement over polling that was previously necessary.

I am wondering though how to enable watching of all files in shared folder on Drive. We are working on Drive monitoring tool, that keeps list of all changes and enables reporting for whole enterprise Drive folders.

I am aware that I can use the notifications about new objects in Changes feed. Unfortunately, you are not able to detect the what has changed from Changes resource.

When watching File resources, you can receive notifications that say what has been changed about the file (parents, permissions, metadata etc.). This is great, however it seems that is not possible to register Push Notification handler for all files in Drive. The docs says you always need to provide fileId. That would mean to make watch requests for millions of files in our scenario (not mentioning renewing the Push API channels each now and then).

Do you know of any more suitable way than using Changes notifications and detect what has been changed manually (which is quite a lot of API calls and rather slow to do).


回答1:


Long story short, no.

Push Notification for now only supports watching on Files and Changes. As you might know, folders in Google Drive is File with special mimeType. That is, you can watch on a specific folder by making Files.Watch() request to a folder. However, it will only tell you changes in its direct children, not recursively, which is probably not what you wanted.

The best approach you could take is to make copy of all file's metadata to your application and compare it when any changes happened. I know this is not very efficient, but for now, this is the only way you could achieve this goal.

And if you ask me if the feature you want will be created, not likely. Push notifications is not only for Drive API. It is designed for all Google API to watch on any API resource and detect their changes. Basically, when you make Files.Watch() request, it keeps copy of the result of Files.get() and let you know when anything changed. That is the reason why Files.watch has a lot more useful details. For Changes, it tells you whenever there is changes in Changes.list(). Thus, it cannot tell you anything better than what Changes resource can currently do. From its design, I don't think the feature you want will be added to Drive API.



来源:https://stackoverflow.com/questions/18144094/google-drive-sdk-push-notifications-watch-changes-on-all-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!