Search code examples
javascriptgoogle-api-js-client

Google calendar API: Event: watch - Channel id must match [A-Za-z0-9\\-_\\+/=]+


I've gone through this example and got it working:

https://developers.google.com/calendar/quickstart/js

I now want to watch for changes to events:

https://developers.google.com/calendar/v3/reference/events/watch

I'm calling the following code after the user clicks a button:

gapi.client.calendar.events.watch({
      calendarId: 'primary',
      resource: {
        id: '1234',
        type: 'web_hook',
        address: window.location.href,
      },
    })

I then get the following error:

{
"error": {
 "errors": [
  {
   "domain": "push",
   "reason": "channelIdInvalid",
   "message": "Channel id must match [A-Za-z0-9\\-_\\+/=]+"
  }
 ],
 "code": 400,
 "message": "Channel id must match [A-Za-z0-9\\-_\\+/=]+"
 }
}

I believe resource.id represents the channel id, which I've set as 1234. I don't really understand what this is or what it should be. The docs are pretty sparse :/

Any help would be really appreciated.

Thanks in advance!


Solution

  • According to the docs you posted it should be something like this

    gapi.client.calendar.events.watch({
      id: 'primary',
      token: '1234',
      type: 'web_hook',
      address: window.location.href,
    })