-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChangedOnly.gs
40 lines (35 loc) · 1.36 KB
/
ChangedOnly.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Experimental, not needed
// https://developers.google.com/apps-script/guides/services/advanced
// https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services
function getPrimaryCalendarChangedEvents(start, end) {
var syncToken = userProperties.getProperty('syncToken');
var request_options = {}
if (syncToken && typeof syncToken != 'undefined') {
request_options.syncToken = syncToken;
} else {
// Sync events up to thirty days in the past.
request_options.timeMin = start.toISOString();
}
try {
Logger.log("Requesting with: "+JSON.stringify(request_options));
response = Calendar.Events.list(getPrimaryCalendar().getId(), request_options);
Logger.log("Setting: "+JSON.stringify(response));
userProperties.setProperty('syncToken', response.nextSyncToken);
if (response.items && response.items.length > 0)
{
return response.items;
} else {
return [];
}
} catch (e) {
// Check to see if the sync token was invalidated by the server;
// if so, perform a full sync instead.
userProperties.deleteProperty('syncToken');
Logger.log("Doing full sync: "+e.message+syncToken);
return getPrimaryCalendarChangedEvents(start, end);
}
}
function sync2() {
var events = getPrimaryCalendarChangedEvents(start_time, end_time);
Logger.log("HOW MANY: "+events.length);
}