简体   繁体   English

Google Calendar API - 推送通知无效

[英]Google Calendar API - Push notifications not working

I'm using the Google Calendar API and am trying to receive push notifications when a calendar event is triggered https://developers.google.com/calendar/v3/push 我正在使用Google Calendar API,并且在触发日历活动时尝试接收推送通知https://developers.google.com/calendar/v3/push

I think everything is setup correctly... 我认为一切都设置正确...

gapi.client.calendar.events.watch({
  calendarId: 'primary',
  resource: {
    id: uuid,
    type: 'web_hook',
    address: window.location.href,
  },
}, (err, response) => {
  if (err) {
    console.log('err:', err);
  } else {
    console.log('response:', response);
  }
}).then((res) => {
  console.log('res:', res);
});

But I guess not. 但我猜不是。 I get a 200 response when I call the above code 当我调用上面的代码时,我收到200响应

{
 "kind": "api#channel",
 "id": "...",
 "resourceId": "...",
 "resourceUri": "https://content.googleapis.com/calendar/v3/calendars/primary/events?alt=json&maxResults=250&alt=json",
 "expiration": "1554203159000"
}

I believe I should also be receiving a sync message, but I am not ( https://developers.google.com/calendar/v3/push#sync ) 我相信我也应该收到同步消息,但我不是( https://developers.google.com/calendar/v3/push#sync

To test things I am modifying an event within the calendar itself (changing the title, date, deleting, etc), and I expect something to happen in my browser, but nothing. 为了测试我正在修改日历本身内的事件(更改标题,日期,删除等),我希望在我的浏览器中发生一些事情,但没有。

I'm not familiar with Push notifications in general, so not exactly sure what to expect. 我一般不熟悉推送通知,所以不确定会发生什么。

I'm already authenticated and displaying events as per https://developers.google.com/calendar/quickstart/js 我已经过身份验证并按照https://developers.google.com/calendar/quickstart/js显示活动

What am I missing? 我错过了什么? Any help is really appreciated! 任何帮助真的很感激!

Thanks in advance! 提前致谢!

I suspect you are miss understanding exactly what push notifications is. 我怀疑你很想知道究竟是什么推送通知。

There are two primary ways to track when a resource has changed. 有两种主要方法可以跟踪资源何时发生变化。 You can poll that resource often and check for any changes in the resource. 您可以经常轮询该资源并检查资源中的任何更改。

For example Your application could run every five minutes and make a request to Google asking to have the event returned to you. 例如,您的应用程序可能每五分钟运行一次,并向Google发出请求,要求将该事件返回给您。 When that event is returned you will then check if there are any changes in the event created by the user. 返回该事件后,您将检查用户创建的事件是否有任何更改。 This method of checking for changes is very time consuming and requires resources to constantly poll the server looking for changes. 这种检查更改的方法非常耗时,并且需要资源来不断轮询服务器以查找更改。 A better way of doing it is using Push notifications 更好的方法是使用推送通知

Push notifications notify your application when a change has been made. 更改完成后, 推送通知会通知您的应用程序。

This document describes how to use push notifications that inform your application when a resource changes . 本文档介绍了如何使用推送通知,在资源发生变化时通知您的应用程序。

Its set up by enabling a watch 它通过启用手表来设置

POST https://www.googleapis.com/calendar/v3/calendars/my_calendar@gmail.com/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json

{
  "id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
  "type": "web_hook",
  "address": "https:/examle.com/notifications", // Your receiving URL.
  ...
  "token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
  "expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}

This tells Googles servers that you would like to be notified when ever someone makes a change to the event. 这告诉Googles服务器,当有人对事件进行更改时,您希望收到通知。 This sets up a web hook to https:/examle.com/notifications which will be notified as soon as there is a change to the event. 这将设置一个https:/examle.com/notifications的Web挂钩,一旦事件发生更改,将立即通知该挂钩。

Name of the event, date time are normally changes i dont think you will get a push notification if someone else is added to the event. 事件的名称,日期时间通常会发生变化我不认为如果其他人被添加到事件中,您将获得推送通知。

What this is not 这不是什么

The server is NOT going to send you a message 10 minutes before the event is due. 服务器不会在事件发生前10分钟向您发送消息。 Thats user notification and something completely different and not part of the Google Calendar api. 这是用户通知和完全不同的东西,而不是Google Calendar api的一部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM