I want to get the color(red) below the picture.
I use next code, but I don’t know next step.
run main function.
JavaScript
x
27
27
1
var mainCalendarName = 'main';
2
3
function main() {
4
var calendar = getCalendar();
5
6
if (calendar == null) {
7
return;
8
}
9
10
var now = new Date();
11
var calendarEventArray = calendar.getEventsForDay(now);
12
13
Logger.log('current color = ' + calendarEventArray[0].getColor()); // not use!!!
14
//log 'current color = #FF0000'
15
}
16
17
function getCalendar() {
18
var calendarList = CalendarApp.getAllCalendars();
19
20
for (i in calendarList) {
21
if (mainCalendarName === calendarList[i].getName()) {
22
return calendarList[i];
23
}
24
}
25
return null;
26
}
27
Advertisement
Answer
First of all you need to enable the Advanced Google Services.
Please see here description how do that.
Then the following code will do the job
JavaScript
1
13
13
1
function main(){
2
var now = new Date();
3
var events = Calendar.Events.list("main", {
4
timeMin: now.toISOString(),
5
singleEvents: true,
6
orderBy: 'startTime',
7
maxResults: 10
8
});
9
for (var i = 0; i < events.items.length; i++) {
10
Logger.log(events.items[i].colorId); //Here the color of the specific event
11
}
12
}
13