Google Drive watch 更改的无服务器解决方案
Serverless Solution for Google Drive watch changes
我想制作一个由 Google Drive "Changes: watch" 触发的 firebase 函数:
https://developers.google.com/drive/api/v3/reference/changes/watch
我知道我可能可以使用 Google 云存储来做到这一点,但对于我的用例来说,让 Google 驱动器监视和上传文件更改对我的用户来说是最好的用户体验。
我希望这是一个无服务器解决方案,可以在 运行 一直处于 waiting/polling 的服务器上省钱。理想情况下,这可以在带有触发器的 firebase 函数中完成,因为我正在将数据解析到 Firestore
您可以使用 Google Drive Push Notifications API.
设置您的 WebHook 以指向您的 firebase 函数端点:
POST https://www.googleapis.com/drive/v3/changes/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "4ba78bf0-6a47-11e2-bcfd-0800200c9a77", // Your channel ID.
"type": "web_hook",
"address": "<your-function-endpoint>", // Your receiving URL.
"token": "target=myApp-myChangesChannelDest", // (Optional) Your channel token.
}
我想制作一个由 Google Drive "Changes: watch" 触发的 firebase 函数:
https://developers.google.com/drive/api/v3/reference/changes/watch
我知道我可能可以使用 Google 云存储来做到这一点,但对于我的用例来说,让 Google 驱动器监视和上传文件更改对我的用户来说是最好的用户体验。
我希望这是一个无服务器解决方案,可以在 运行 一直处于 waiting/polling 的服务器上省钱。理想情况下,这可以在带有触发器的 firebase 函数中完成,因为我正在将数据解析到 Firestore
您可以使用 Google Drive Push Notifications API.
设置您的 WebHook 以指向您的 firebase 函数端点:
POST https://www.googleapis.com/drive/v3/changes/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "4ba78bf0-6a47-11e2-bcfd-0800200c9a77", // Your channel ID.
"type": "web_hook",
"address": "<your-function-endpoint>", // Your receiving URL.
"token": "target=myApp-myChangesChannelDest", // (Optional) Your channel token.
}