Reputation: 2869
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.
X-Goog-Resource-Id
which I'd thought might be the new file, but I get a 404 if I try to get()
itX-Goog-Resource-Uri
, but that belongs to the watched folderX-Goog-Channel-Id
, but that clearly belongs to the channel not the fileX-Request-Id
, but that's just an opaque UUIDAm 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.
Upvotes: 8
Views: 6477
Reputation: 63
After watch request, you will start receiving the notifications about changes via webhook, you can request a pagetoken from drive API, and fetch all the changes from that page token, each change will have entire data, file is added/removed/trashed/updated. Store the token from response, so that next time you fetch all new changes from that token
For more information, refer this video
Upvotes: -1
Reputation: 716
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!
Upvotes: 2
Reputation: 800
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.
Upvotes: 1