8

I have a test endpoint running and when I drop a file into the watched folder I get a request with the header X-Goog-Resource-State: update, but I don't seem to get an Id for the added file.

  • I get X-Goog-Resource-Id which I'd thought might be the new file, but I get a 404 if I try to get() it
  • I get X-Goog-Resource-Uri, but that belongs to the watched folder
  • I get an X-Goog-Channel-Id, but that clearly belongs to the channel not the file
  • And X-Request-Id, but that's just an opaque UUID

Am I required to fetch a complete list of files for the watched folder on every update and compare to a saved list? That doesn't feel right, but I'm at a loss.

Any guidance would be much appreciated.

CJ Thompson
  • 2,729
  • 2
  • 22
  • 26
  • According to the documentation, "update" implies that the folder -- itself -- was updated (not an addition to the folder). Otherwise, you should get an "add" event. The endpoint should also receive an X-Goog-Changed header indicating what portion of the resource was updated. – Michael Aaron Safyan Oct 21 '15 at 04:34
  • See: https://developers.google.com/drive/web/push#understanding-drive-api-notification-events – Michael Aaron Safyan Oct 21 '15 at 04:35
  • Thank you for the link, adding that one to my doc list. But I don't get an `add` event, just `update`. There is an `X-Goog-Changed` header indicating `children`, but nothing identifying the child – CJ Thompson Oct 21 '15 at 04:56

2 Answers2

2

Is there any better way of doing this today? After searching the Drive API Docs it doesn't appear that it has changed.

I'll throw another idea out there if it has not changed. What I will probably end up doing is creating 2 folders, one for New Items and one for Processed Items. I'll watch the New Items folder and when notified, I'll process any files in the folder and move them to the Processed Items folder. Just personal preference on this one but I'd prefer not to change the files' properties or modify them in any way and I'd be a little paranoid that if I get them by time created I'd either process some files more than once or somehow one would get left out here or there.

It would be great to be able to receive notifications of added files including their IDs though!

zpert
  • 706
  • 9
  • 18
  • 1
    To my knowledge, nothing has changed. We all but abandoned this functionality until they fix/add it, as it was too cumbersome to watch an *entire* Drive for *all* changes only to discard 98% of them. – CJ Thompson Dec 09 '17 at 21:08
  • 1
    22/02/2021: Nothing has changed. – Erowlin Feb 22 '21 at 16:33
1

I was in the same situation and ended up passing the watched folder (file)id in the token field of the watch channel. When an event occurs, I fetch the list of files included in that folder. I didn't need to compare with any other list as all new files are not owned by my default account so they were easy to be found, but in your case you could search for files created in the last seconds/minutes or use a private property for all processed files and search for all files missing that property.

Dany Gauthier
  • 800
  • 6
  • 16
  • I don't think you can search for file "not having a property". If that is possible can you share such a query? I think that you can only search for file "having particular value of that private property". – vajanko Jul 24 '20 at 10:47
  • @vajanko, I think you can (sorry I cannot test it easily anymore). I would try something like not appProperties has 'you property name'. Here are examples for querying files : https://developers.google.com/drive/api/v3/ref-search-terms#file_properties. Look at the appProperties term at the end of the table. – Dany Gauthier Feb 12 '21 at 15:00
  • thanks for suggestion. I have tried that. The query must have this format properties has { key = 'property_name' and value = 'property_value' }. The other format properties has { key = 'property_name' } is not allowed and API returns an error. Also properties has { key = 'property_name' and value = NULL } and other variants are invalid. – vajanko Feb 14 '21 at 16:02
  • Did you manage to make something like "NOT { key = 'property_name' and value = 'property_value' }" work? If so you can set the value to something specific for all files that have been processed. – Dany Gauthier Feb 15 '21 at 19:30
  • 1
    that's right. At the end I did exactly what you have suggested. But it's not a nice solution in my case. Anyway, thanks for your help. – vajanko Mar 04 '21 at 16:03