如何检测 Google 日历事件推送通知回调中的用户?

huangapple go评论55阅读模式
英文:

How to detect the user on google calendar events push notification callback?

问题

我正在尝试将预订系统与Google日历和Google资源进行双向同步。

为了做到这一点,我在特定的Google资源日历上创建了Webhook通道,以便了解事件的创建(即预订资源会议室)、更新和删除。这部分运作正常 - 每当用户创建事件时,我们的后端都会通过Google推送通知得到通知,我也可以在我们的系统中查找相应的会议室进行预订。

但问题是,我无法区分是哪个用户执行了操作!根据Google推送通知的信息,我在回调数据中找不到有关用户信息的任何内容。是否有解决方案?

回调通知中的标头数据:

Host: f73b-98-14-18-68.eu.ngrok.io
User-Agent: APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)
Content-Length: 0
Accept: */*
Accept-Encoding: gzip, deflate, br
X-Forwarded-For: 74.125.210.217
X-Forwarded-Proto: https
X-Goog-Channel-Expiration: Thu, 02 Mar 2023 06:34:05 GMT
X-Goog-Channel-Id: 12345678904
X-Goog-Message-Number: 6863357
X-Goog-Resource-Id: szg7mO63iJ_3oMLRGXyv7868CQQ
X-Goog-Resource-State: exists
X-Goog-Resource-Uri: https://www.googleapis.com/calendar/v3/calendars/c_1887qe9rpoms8hdanb029mmhoiira%40resource.calendar.google.com/events?alt=json

Google日历事件观察API
接收通知

英文:

I am trying to sync a booking system with google calendar and google resource as two-way synchronization.

To do that, I creates webhook channels on specific google resource calendars to be aware of creating events (i.e. booking a resource room), updating, and deleting. It works fine — whenever a user creates an event out backend got notified by the google push notification and I can fetch the respective meeting room in our system as well for booking.

But the problem is, I cannot distinguish which user was that! According to the google push notification information I couldn't find any thing about the user information on the callback data. Is there any solution?

Data of header in callback notification:

Host: f73b-98-14-18-68.eu.ngrok.io
User-Agent: APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)
Content-Length: 0
Accept: */*
Accept-Encoding: gzip, deflate, br
X-Forwarded-For: 74.125.210.217
X-Forwarded-Proto: https
X-Goog-Channel-Expiration: Thu, 02 Mar 2023 06:34:05 GMT
X-Goog-Channel-Id: 12345678904
X-Goog-Message-Number: 6863357
X-Goog-Resource-Id: szg7mO63iJ_3oMLRGXyv7868CQQ
X-Goog-Resource-State: exists
X-Goog-Resource-Uri: https://www.googleapis.com/calendar/v3/calendars/c_1887qe9rpoms8hdanb029mmhoiira%40resource.calendar.google.com/events?alt=json

Google calendar events watch API
Receiving notification

答案1

得分: 1

推送通知的目的是为了以低吞吐量的方式检查日历的更改,因此它只包含通道的ID和日历的ID。目前还没有办法在推送通知中获取特定的事件信息。

您的选择是将通知与其他API结合使用。例如:

  • 使用增量同步。这使用同步令牌仅检索自上次同步以来更改的事件,因此您可以在收到通知时同步。 事件对象具有creator字段,因此您可以知道谁创建了它。
  • 可能更准确的是,您可以使用报告API activities.list 检查applicationName = calendar,以查看谁对日历和事件进行了更改。您可以在收到通知后触发搜索,并过滤结果以获取通知后的所有更改。缺点是生成日志可能会有一些延迟

总的来说,单独的推送通知不能告诉您谁进行了更改,因为它们的作用只是通知您某事已经发生了变化,但您之后有几种获取信息的方式。

英文:

The push notifications are meant to just be a low-throughput way to check for changes to the Calendar, so it only contains the ID of the channel and the calendar ID. Currently there's no way to get specific event info in the push notification.

Your options are to combine the notifications with other APIs. For example:

  • Use incremental sync. This uses sync tokens to retrieve only the changed events from the last sync, so you can sync whenever you get a notification. The event object has a creator field so you can know who created it.
  • Probably more accurate, you can check the Reports API activities.list
    with applicationName = calendar to check who made changes to the Calendar and to which events. You can trigger a search after you get a notification and filter results to get all changes from the time after you got the notification. The downside is that there may be some delay for the logs to be generated.

The bottom line is that the push notifications by themselves cannot tell you who made the change, since their job is just to notify you that something changed, but you have a few ways to get the info afterwards.

huangapple
  • 本文由 发表于 2023年2月24日 14:56:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75553419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定