admin管理员组文章数量:1415645
Background
I've been setting up a push-notification client in node.js to watch for changes in calendars/events for a user. Setting up calendar.events.watch
works perfectly, I receive the sync
notification at myapp/notifications as well as all push notifications denoting changes in calendars.
Problem
Now, when needing to poll for these updated events, I found it best done by following Google's Synchronize Resources walkthrough in order to grab a syncToken
and grab events incrementally. In their java example, it makes sense how they obtain, store, and refresh the syncToken
's. However, I cannot seem to find any kind of documentation (or anyone else using them) for node.js.
Question
How do you obtain that initial syncToken
to perform the initial sync on a calendar? Either I've been searching for the wrong keywords or the feature isn't currently supported in the node.js framework, which I would find surprising.
Context
Here is my code for what I interpret to be the "full initial sync." This is a continuation of the Quickstart listed here.
var google = require('googleapis');
...
function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
auth: auth,
calendarId: 'ZZZZZZZZZZZZZZZZZZZ',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var events = response.items;
console.log(response);
});
}
The console.log(response);
statement returns...
{ kind: 'calendar#events',
etag: '"**redacted**"',
summary: '[email protected]',
updated: '2016-07-19T00:34:55.921Z',
timeZone: 'America/New_York',
accessRole: 'owner',
defaultReminders: [ { method: 'popup', minutes: 30 } ],
items:
[ { kind: 'calendar#event',
etag: '"**redacted**"',
id: '**redacted**',
status: 'confirmed',
htmlLink: '=**redacted**',
created: '2016-07-19T00:34:55.000Z',
updated: '2016-07-19T00:34:55.715Z',
summary: 'Thing',
creator: [Object],
organizer: [Object],
start: [Object],
end: [Object],
iCalUID: '**redacted**@google',
sequence: 0,
reminders: [Object] } ] }
Should that nextSyncToken
be found in here?
Background
I've been setting up a push-notification client in node.js to watch for changes in calendars/events for a user. Setting up calendar.events.watch
works perfectly, I receive the sync
notification at myapp./notifications as well as all push notifications denoting changes in calendars.
Problem
Now, when needing to poll for these updated events, I found it best done by following Google's Synchronize Resources walkthrough in order to grab a syncToken
and grab events incrementally. In their java example, it makes sense how they obtain, store, and refresh the syncToken
's. However, I cannot seem to find any kind of documentation (or anyone else using them) for node.js.
Question
How do you obtain that initial syncToken
to perform the initial sync on a calendar? Either I've been searching for the wrong keywords or the feature isn't currently supported in the node.js framework, which I would find surprising.
Context
Here is my code for what I interpret to be the "full initial sync." This is a continuation of the Quickstart listed here.
var google = require('googleapis');
...
function listEvents(auth) {
var calendar = google.calendar('v3');
calendar.events.list({
auth: auth,
calendarId: 'ZZZZZZZZZZZZZZZZZZZ',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime'
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var events = response.items;
console.log(response);
});
}
The console.log(response);
statement returns...
{ kind: 'calendar#events',
etag: '"**redacted**"',
summary: '[email protected]',
updated: '2016-07-19T00:34:55.921Z',
timeZone: 'America/New_York',
accessRole: 'owner',
defaultReminders: [ { method: 'popup', minutes: 30 } ],
items:
[ { kind: 'calendar#event',
etag: '"**redacted**"',
id: '**redacted**',
status: 'confirmed',
htmlLink: 'https://www.google./calendar/event?eid=**redacted**',
created: '2016-07-19T00:34:55.000Z',
updated: '2016-07-19T00:34:55.715Z',
summary: 'Thing',
creator: [Object],
organizer: [Object],
start: [Object],
end: [Object],
iCalUID: '**redacted**@google.',
sequence: 0,
reminders: [Object] } ] }
Should that nextSyncToken
be found in here?
2 Answers
Reset to default 4You do an initial full sync (which does not require a syncToken) and as part of that full sync response, you get all the current calendar items and (on the last page if the results are paged) you get a field called nextSyncToken
. You then use that nextSyncToken
value for the next incremental sync.
From the doc on initial full sync:
In the response to the list operation, you will find a field called nextSyncToken representing a sync token. You'll need to store the value of nextSyncToken. If the result set is too large and the response gets paginated, then the nextSyncToken field is present only on the very last page.
You have to store the sync token until you do the next incremental sync and you present that token as part of the incremental sync request. When you do the next incremental sync, it will then give you a new syncToken
which you will again store and use for the next incremental sync.
This syncToken
is how Google knows which change events to send you since your last sync.
I found that the response does contain 'nextSyncToken' only when the query parameter 'orderBy' is excluded from the request.
All of the unsupported query parameters for using sync tokens are documented at https://developers.google./calendar/v3/reference/events/list under the headline nextSyncToken.
本文标签: javascriptSynchronize Resources with Google Calendar for nodejsStack Overflow
版权声明:本文标题:javascript - Synchronize Resources with Google Calendar for node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745241157a2649335.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论