I am trying to watch for changes in a Google drive folder. I have attempted to subscribe to changes to the folder and I get a response back.
My code for subscribing:
while True:
body = {
"id": str(uuid4()),
"type": "web_hook",
"address": WEBSITE
}
return drive.files().watch(fileId=file_id, body=body).execute()
I get a response back saying the subscription has been accepted. Then my code for the action when there is a change:
return flask.redirect(flask.url_for('parse_doc'))
The parse_doc parses a file and uploads it to another Google Drive folder. I have then tried to upload a new file to the "watched" folder. Despite getting a yes for the subscription, the parse_doc function does not appear to ever be called.
Am I missing something? Anytime there is a change in my "watched" folder (like an upload), shouldn't Google be hitting my endpoint and the function should be called? Thanks for all of your help!
I can reproduce it, but I think that parse_doc
is never been called because the watcher does not follow your URL redirection: a 200 response code is expected, instead, a 301 redirection is received.
If you check the documentation for push notifications on Drive it looks like this redirection is certainly the source of your problems:
Responding to notifications:
To indicate success, you can return any of the following status codes: 200, 201, 202, 204, or 102. If your service returns 500, 502, 503, or 504, the Drive API will retry with exponential backoff.
Every other return status code is considered to be a message failure and the Drive API will not retry this particular notification.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.