Google javascript API library - Calendar view notifications

I am trying to subscribe to calendar event notifications in the JS client library as follows:

gapi.client.load('calendar', 'v3', function () {
            var request = gapi.client.calendar.events.watch({
                'calendarId': cl.gCalendarID,
                'id': unid,
                'type': "web_hook",
                'address': {my url here}
            });
            request.execute(function (resp) {
                console.log(resp);
            });
        });

But I just get 400 returned with a useless message " Entity.Resource"

In the response data object, I get Domain:global, Message: Entity.Resource, reason: Required"

I have already authenticated with oauth2, and I have granted access to my Google account, and I can successfully get the list of calendars, and I extract calendars from them, but this method for subscribing to the clock will not work? Please help, I can’t find anything on Google.

+4
source share
2 answers
Instead of this:


 var request = gapi.client.calendar.events.watch({
                'calendarId': cl.gCalendarID,
                'id': unid,
                'type': "web_hook",
                'address': {my url here}
            });

You use this syntax:

calendar.events.watch({
            auth: auth,
                resource: {
                    id: "12345",
                    type: 'web_hook',
                    address: {mu url here}
                 },
                calendarId: 'primary' 

            }, function(err, response) {
                if (err) {
                    logger.MessageQueueLog.log("info","index.js:- watchnotification(),Error in Watch Notification: " + err);

                } else {          
                   logger.MessageQueueLog.log("info","index.js:- watchnotification(), Notification : " + JSON.stringify(response));           

                }
            });

Hope this works.

+5

, API , , .

{
  "id": string,
  "token": string,
  "type": string,
  "address": string,
  "params": {
  "ttl": string
 }
}

.

Google Calendar API

0

All Articles