收到新电子邮件时Gmail API/Pub子发送2条消息
每当电子邮件到达邮箱时,我都在尝试触发Google Cloud功能。
我已经使用Google Cloud功能配置了Pub子订阅,并使用“ PUSH”输送类型配置。
我还配置了Gmail帐户以将通知发送到我的Cloud Pub/sub主题,
request = {
'labelIds': ['INBOX'],
'labelFilterAction': 'include,
'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()
问题是我每次到达新电子邮件时都会在同一Milisecond中收到2个酒吧sub消息:
labelfilteraction
和labelids
,但没有任何变化。我总是收到2条消息。
关于为什么2条消息以及如何避免它们的任何解释?
提前致谢
I'm trying to trigger a Google cloud function every time an email arrives to the mailbox.
I have configured the pub sub subscription with the Google Cloud Function with "PUSH" Delivery Type.
I have also configure Gmail account to send notifications to my Cloud Pub/Sub topic,
request = {
'labelIds': ['INBOX'],
'labelFilterAction': 'include,
'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()
The problem is that I receive 2 pub sub messages in the same milisecond every time a new email arrives:
I have tried changing the labelFilterAction
and labelIds
but nothing change. I always receive 2 messages.
Any explanation about why 2 messages and how to avoid them?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经在收件箱标签中提出了手表请求,
当收件箱中收到消息时,您可能会收到通知,第二个可能是在读取或移动消息时。
另外,请确保您没有发表多个手表请求
该手表方法(订阅有关用户收件箱的通知)应该是不应该的。尽管情况很广泛,但如果您同时发送多个手表请求,则最终获得了多个订阅,这意味着该用户的每个事件都会多次将其推向您的端点!
确保停止上一个手表请求或如果您保存了手表响应,则手表响应包括到期时间使用该响应,以使下一个手表请求
You have made a watch request in INBOX label,
you might be receiving notification when a message is received in the inbox and the second maybe when the message is read or moved.
also make sure you are not making multiple watch requests
The watch method (which subscribes to notifications regarding a user’s inbox) is supposed to be idempotent. While that’s broadly the case, if you send multiple watch requests simultaneously, you end up with multiple subscriptions, meaning every event for that user gets pushed to your endpoint multiple times!
make sure to stop the previous watch request or if you are saving the watch response, the watch response includes an expiration time use that to make the next watch request