Class CalendarApp

แอปปฏิทิน

อนุญาตให้สคริปต์อ่านและอัปเดต Google ปฏิทินของผู้ใช้ คลาสนี้ให้สิทธิ์เข้าถึงโดยตรง ไปยังปฏิทินเริ่มต้นของผู้ใช้ รวมถึงความสามารถในการเรียกปฏิทินเพิ่มเติมที่ ผู้ใช้เป็นเจ้าของหรือติดตามอยู่

พร็อพเพอร์ตี้

พร็อพเพอร์ตี้ประเภทคำอธิบาย
ColorColorการแจงนับที่แสดงสีที่มีชื่อซึ่งพร้อมใช้งานในบริการปฏิทิน
EventColorEventColorการแจงนับที่แสดงสีของกิจกรรมที่มีชื่อซึ่งพร้อมใช้งานในบริการปฏิทิน
EventTransparencyEventTransparencyEventTransparencyการแจงนับ
EventTypeEventTypeEventTypeการแจงนับ
GuestStatusGuestStatusการแจงนับที่แสดงสถานะที่ผู้เข้าร่วมมีได้สำหรับกิจกรรม
MonthMonthการแจงนับที่แสดงเดือนของปี
VisibilityVisibilityการแจงนับที่แสดงถึงระดับการเข้าถึงของกิจกรรม
WeekdayWeekdayการแจงนับที่แสดงวันในสัปดาห์

เมธอด

วิธีการประเภทการแสดงผลรายละเอียดแบบย่อ
createAllDayEvent(title, date)CalendarEventสร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน
createAllDayEvent(title, startDate, endDate)CalendarEventสร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดทั้งวันซึ่งอาจกินเวลาหลายวัน
createAllDayEvent(title, startDate, endDate, options)CalendarEventสร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดทั้งวันซึ่งอาจกินเวลาหลายวัน
createAllDayEvent(title, date, options)CalendarEventสร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน
createAllDayEventSeries(title, startDate, recurrence)CalendarEventSeriesสร้างชุดกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน
createAllDayEventSeries(title, startDate, recurrence, options)CalendarEventSeriesสร้างชุดกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน
createCalendar(name)Calendarสร้างปฏิทินใหม่ที่ผู้ใช้เป็นเจ้าของ
createCalendar(name, options)Calendarสร้างปฏิทินใหม่ที่ผู้ใช้เป็นเจ้าของ
createEvent(title, startTime, endTime)CalendarEventสร้างกิจกรรมใหม่
createEvent(title, startTime, endTime, options)CalendarEventสร้างกิจกรรมใหม่
createEventFromDescription(description)CalendarEventสร้างกิจกรรมจากคำอธิบายรูปแบบอิสระ
createEventSeries(title, startTime, endTime, recurrence)CalendarEventSeriesสร้างซีรีส์กิจกรรมใหม่
createEventSeries(title, startTime, endTime, recurrence, options)CalendarEventSeriesสร้างซีรีส์กิจกรรมใหม่
getAllCalendars()Calendar[]รับปฏิทินทั้งหมดที่ผู้ใช้เป็นเจ้าของหรือติดตาม
getAllOwnedCalendars()Calendar[]รับปฏิทินทั้งหมดที่ผู้ใช้เป็นเจ้าของ
getCalendarById(id)Calendar|nullรับปฏิทินที่มีรหัสที่ระบุ
getCalendarsByName(name)Calendar[]รับปฏิทินทั้งหมดที่มีชื่อที่ระบุซึ่งผู้ใช้เป็นเจ้าของหรือติดตาม
getColor()Stringรับสีของปฏิทิน
getDefaultCalendar()Calendarรับปฏิทินเริ่มต้นของผู้ใช้
getDescription()Stringรับคำอธิบายของปฏิทิน
getEventById(iCalId)CalendarEventรับกิจกรรมที่มีรหัสที่ระบุ
getEventSeriesById(iCalId)CalendarEventSeriesรับชุดกิจกรรมที่มีรหัสที่ระบุ
getEvents(startTime, endTime)CalendarEvent[]รับเหตุการณ์ทั้งหมดที่เกิดขึ้นภายในช่วงเวลาที่กำหนด
getEvents(startTime, endTime, options)CalendarEvent[]รับเหตุการณ์ทั้งหมดที่เกิดขึ้นภายในช่วงเวลาที่กำหนดและเป็นไปตามเกณฑ์ที่ระบุ
getEventsForDay(date)CalendarEvent[]รับเหตุการณ์ทั้งหมดที่เกิดขึ้นในวันหนึ่งๆ
getEventsForDay(date, options)CalendarEvent[]รับเหตุการณ์ทั้งหมดที่เกิดขึ้นในวันที่ระบุและตรงตามเกณฑ์ที่ระบุ
getId()Stringรับรหัสของปฏิทิน
getName()Stringรับชื่อปฏิทิน
getOwnedCalendarById(id)Calendar|nullรับปฏิทินที่มีรหัสที่ระบุ หากผู้ใช้เป็นเจ้าของ
getOwnedCalendarsByName(name)Calendar[]รับปฏิทินทั้งหมดที่มีชื่อที่ระบุซึ่งผู้ใช้เป็นเจ้าของ
getTimeZone()Stringรับเขตเวลาของปฏิทิน
isHidden()Booleanกำหนดว่าจะซ่อนปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่
isMyPrimaryCalendar()Booleanกำหนดว่าปฏิทินเป็นปฏิทินหลักสำหรับผู้ใช้ที่มีผลหรือไม่
isOwnedByMe()Booleanระบุว่าคุณเป็นเจ้าของปฏิทินหรือไม่
isSelected()Booleanกำหนดว่าจะแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่
newRecurrence()EventRecurrenceสร้างออบเจ็กต์การเกิดซ้ำใหม่ ซึ่งใช้สร้างกฎสำหรับการเกิดซ้ำของเหตุการณ์ได้
setColor(color)Calendarตั้งค่าสีของปฏิทิน
setDescription(description)Calendarตั้งค่าคำอธิบายของปฏิทิน
setHidden(hidden)Calendarกำหนดว่าจะให้ปฏิทินปรากฏในอินเทอร์เฟซผู้ใช้หรือไม่
setName(name)Calendarตั้งชื่อปฏิทิน
setSelected(selected)Calendarกำหนดว่าจะแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่
setTimeZone(timeZone)Calendarตั้งค่าเขตเวลาของปฏิทิน
subscribeToCalendar(id)Calendarติดตามปฏิทินของผู้ใช้ด้วยรหัสที่ระบุ หากผู้ใช้ได้รับอนุญาตให้ติดตาม
subscribeToCalendar(id, options)Calendarติดตามปฏิทินของผู้ใช้ด้วยรหัสที่ระบุ หากผู้ใช้ได้รับอนุญาตให้ติดตาม

เอกสารโดยละเอียด

createAllDayEvent(title, date)

สร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน

// Creates an all-day event for the moon landing and logs the ID.
const event = CalendarApp.getDefaultCalendar().createAllDayEvent(
    'Apollo 11 Landing',
    new Date('July 20, 1969'),
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อกิจกรรม
dateDateวันที่ของกิจกรรม (ใช้เฉพาะวัน ส่วนเวลาจะถูกละเว้น)

รีเทิร์น

CalendarEvent — กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEvent(title, startDate, endDate)

สร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดทั้งวันซึ่งอาจกินเวลาหลายวัน

// Creates an all-day event for the Woodstock festival (August 15th to 17th) and
// logs the ID.
const event = CalendarApp.getDefaultCalendar().createAllDayEvent(
    'Woodstock Festival',
    new Date('August 15, 1969'),
    new Date('August 18, 1969'),
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อกิจกรรม
startDateDateวันที่กิจกรรมเริ่มต้น (ใช้เฉพาะวัน ส่วนระบบจะไม่สนใจเวลา)
endDateDateวันที่กิจกรรมสิ้นสุด (ใช้เฉพาะวัน ไม่สนใจเวลา) โดย วันที่สิ้นสุดจะไม่รวมอยู่ในช่วง

รีเทิร์น

CalendarEvent — กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEvent(title, startDate, endDate, options)

สร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดทั้งวันซึ่งอาจกินเวลาหลายวัน

// Creates an all-day event for the Woodstock festival (August 15th to 17th) and
// logs the ID.
const event = CalendarApp.getDefaultCalendar().createAllDayEvent(
    'Woodstock Festival',
    new Date('August 15, 1969'),
    new Date('August 18, 1969'),
    {location: 'Bethel, White Lake, New York, U.S.', sendInvites: true},
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อกิจกรรม
startDateDateวันที่กิจกรรมเริ่มต้น (ใช้เฉพาะวัน ส่วนระบบจะไม่สนใจเวลา)
endDateDateวันที่กิจกรรมสิ้นสุด (ใช้เฉพาะวัน ไม่สนใจเวลา) โดย วันที่สิ้นสุดจะไม่รวมอยู่ในช่วง
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายของกิจกรรม
locationStringสถานที่จัดกิจกรรม
guestsStringรายชื่ออีเมลที่คั่นด้วยคอมมาซึ่งควรเพิ่ม เป็นผู้เข้าร่วม
sendInvitesBooleanจะส่งอีเมลคำเชิญหรือไม่ (ค่าเริ่มต้น: false)

รีเทิร์น

CalendarEvent — กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEvent(title, date, options)

สร้างกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน

// Creates an all-day event for the moon landing and logs the ID.
const event = CalendarApp.getDefaultCalendar().createAllDayEvent(
    'Apollo 11 Landing',
    new Date('July 20, 1969'),
    {location: 'The Moon'},
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อกิจกรรม
dateDateวันที่ของกิจกรรม (ใช้เฉพาะวัน ส่วนเวลาจะถูกละเว้น)
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายของกิจกรรม
locationStringสถานที่จัดกิจกรรม
guestsStringรายชื่ออีเมลที่คั่นด้วยคอมมาซึ่งควรเพิ่ม เป็นผู้เข้าร่วม
sendInvitesBooleanจะส่งอีเมลคำเชิญหรือไม่ (ค่าเริ่มต้น: false)

รีเทิร์น

CalendarEvent — กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEventSeries(title, startDate, recurrence)

สร้างชุดกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน

// Creates an event series for a no-meetings day, taking place every Wednesday
// in 2013.
const eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries(
    'No Meetings',
    new Date('January 2, 2013 03:00:00 PM EST'),
    CalendarApp.newRecurrence()
        .addWeeklyRule()
        .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
        .until(new Date('January 1, 2014')),
);
Logger.log(`Event Series ID: ${eventSeries.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อของกิจกรรมในชุด
startDateDateวันที่ของเหตุการณ์แรกในชุด (ใช้เฉพาะวัน เวลาจะถูก ละเว้น)
recurrenceEventRecurrenceการตั้งค่าการเกิดซ้ำของชุดกิจกรรม

รีเทิร์น

CalendarEventSeries - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createAllDayEventSeries(title, startDate, recurrence, options)

สร้างชุดกิจกรรมใหม่ที่เกิดขึ้นตลอดวัน

// Creates an event series for a no-meetings day, taking place every Wednesday
// in 2013.
const eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries(
    'No Meetings',
    new Date('January 2, 2013 03:00:00 PM EST'),
    CalendarApp.newRecurrence()
        .addWeeklyRule()
        .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
        .until(new Date('January 1, 2014')),
    {guests: 'everyone@example.com'},
);
Logger.log(`Event Series ID: ${eventSeries.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อของกิจกรรมในชุด
startDateDateวันที่ของเหตุการณ์แรกในชุด (ใช้เฉพาะวัน เวลาจะถูก ละเว้น)
recurrenceEventRecurrenceการตั้งค่าการเกิดซ้ำของชุดกิจกรรม
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายกิจกรรมในชุด
locationStringสถานที่จัดกิจกรรมในชุด
guestsStringรายชื่ออีเมลที่คั่นด้วยคอมมาซึ่งควรเพิ่ม เป็นผู้เข้าร่วมในกิจกรรมในชุด
sendInvitesBooleanว่าจะส่งอีเมลคำเชิญหรือไม่ (ค่าเริ่มต้น: false)

รีเทิร์น

CalendarEventSeries - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createCalendar(name)

สร้างปฏิทินใหม่ที่ผู้ใช้เป็นเจ้าของ

// Creates a new calendar named "Travel Plans".
const calendar = CalendarApp.createCalendar('Travel Plans');
Logger.log(
    'Created the calendar "%s", with the ID "%s".',
    calendar.getName(),
    calendar.getId(),
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของปฏิทินใหม่

รีเทิร์น

Calendar - ปฏิทินที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createCalendar(name, options)

สร้างปฏิทินใหม่ที่ผู้ใช้เป็นเจ้าของ

// Creates a new calendar named "Travel Plans" with a description and color.
const calendar = CalendarApp.createCalendar('Travel Plans', {
  description: 'A calendar to plan my travel schedule.',
  color: CalendarApp.Color.BLUE,
});
Logger.log(
    'Created the calendar "%s", with the ID "%s".',
    calendar.getName(),
    calendar.getId(),
);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อของปฏิทินใหม่
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
locationStringตำแหน่งของปฏิทิน
descriptionStringคำอธิบายของปฏิทิน
timeZoneStringเขตเวลาที่จะตั้งค่าปฏิทิน ซึ่งระบุในรูปแบบ "ยาว" (เช่น "America/New_York" ตามที่ระบุไว้ใน Joda.org)
colorStringสตริงสีแบบเลขฐานสิบหก ("#rrggbb") หรือค่าจาก CalendarApp.Colors
hiddenBooleanไม่ว่าจะซ่อนปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่ (ค่าเริ่มต้น: false)
selectedBooleanว่าจะแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่ (ค่าเริ่มต้น: true)

รีเทิร์น

Calendar - ปฏิทินที่สร้างขึ้นใหม่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEvent(title, startTime, endTime)

สร้างกิจกรรมใหม่

หากไม่ได้ระบุเขตเวลา ระบบจะตีความค่าเวลาในบริบทของเขตเวลาของสคริปต์ ซึ่งอาจแตกต่างจากเขตเวลาของปฏิทิน

// Creates an event for the moon landing and logs the ID.
const event = CalendarApp.getDefaultCalendar().createEvent(
    'Apollo 11 Landing',
    new Date('July 20, 1969 20:00:00 UTC'),
    new Date('July 21, 1969 21:00:00 UTC'),
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อกิจกรรม
startTimeDateวันที่และเวลาที่กิจกรรมเริ่ม
endTimeDateวันที่และเวลาที่กิจกรรมสิ้นสุด

รีเทิร์น

CalendarEvent - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEvent(title, startTime, endTime, options)

สร้างกิจกรรมใหม่

หากไม่ได้ระบุเขตเวลา ระบบจะตีความค่าเวลาในบริบทของเขตเวลาของสคริปต์ ซึ่งอาจแตกต่างจากเขตเวลาของปฏิทิน

// Creates an event for the moon landing and logs the ID.
const event = CalendarApp.getDefaultCalendar().createEvent(
    'Apollo 11 Landing',
    new Date('July 20, 1969 20:00:00 UTC'),
    new Date('July 20, 1969 21:00:00 UTC'),
    {location: 'The Moon'},
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อกิจกรรม
startTimeDateวันที่และเวลาที่กิจกรรมเริ่ม
endTimeDateวันที่และเวลาที่กิจกรรมสิ้นสุด
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายกิจกรรม
locationStringสถานที่จัดกิจกรรม
guestsStringรายชื่ออีเมลที่คั่นด้วยคอมมาซึ่งควรเพิ่ม เป็นแขกรับเชิญ
sendInvitesBooleanว่าจะส่งอีเมลคำเชิญหรือไม่ (ค่าเริ่มต้น: false)

รีเทิร์น

CalendarEvent - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventFromDescription(description)

สร้างกิจกรรมจากคำอธิบายรูปแบบอิสระ

คำอธิบายควรใช้รูปแบบเดียวกับฟีเจอร์"เพิ่มด่วน" ของ UI

// Creates a new event and logs its ID.
const event = CalendarApp.getDefaultCalendar().createEventFromDescription(
    'Lunch with Mary, Friday at 1PM',
);
Logger.log(`Event ID: ${event.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายเหตุการณ์แบบอิสระ

รีเทิร์น

CalendarEvent - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventSeries(title, startTime, endTime, recurrence)

สร้างซีรีส์กิจกรรมใหม่

// Creates an event series for a team meeting, taking place every Tuesday and
// Thursday in 2013.
const eventSeries = CalendarApp.getDefaultCalendar().createEventSeries(
    'Team Meeting',
    new Date('January 1, 2013 03:00:00 PM EST'),
    new Date('January 1, 2013 04:00:00 PM EST'),
    CalendarApp.newRecurrence()
        .addWeeklyRule()
        .onlyOnWeekdays(
            [CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY])
        .until(new Date('January 1, 2014')),
);
Logger.log(`Event Series ID: ${eventSeries.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อของกิจกรรมในชุด
startTimeDateวันที่และเวลาที่กิจกรรมแรกในชุดเริ่มต้น
endTimeDateวันที่และเวลาที่เหตุการณ์แรกในชุดสิ้นสุด
recurrenceEventRecurrenceการตั้งค่าการเกิดซ้ำของชุดกิจกรรม

รีเทิร์น

CalendarEventSeries - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

createEventSeries(title, startTime, endTime, recurrence, options)

สร้างซีรีส์กิจกรรมใหม่

// Creates an event series for a team meeting, taking place every Tuesday and
// Thursday in 2013.
const eventSeries = CalendarApp.getDefaultCalendar().createEventSeries(
    'Team Meeting',
    new Date('January 1, 2013 03:00:00 PM EST'),
    new Date('January 1, 2013 04:00:00 PM EST'),
    CalendarApp.newRecurrence()
        .addWeeklyRule()
        .onlyOnWeekdays(
            [CalendarApp.Weekday.TUESDAY, CalendarApp.Weekday.THURSDAY])
        .until(new Date('January 1, 2014')),
    {location: 'Conference Room'},
);
Logger.log(`Event Series ID: ${eventSeries.getId()}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
titleStringชื่อของกิจกรรมในชุด
startTimeDateวันที่และเวลาที่กิจกรรมแรกในชุดเริ่มต้น
endTimeDateวันที่และเวลาที่เหตุการณ์แรกในชุดสิ้นสุด
recurrenceEventRecurrenceการตั้งค่าการเกิดซ้ำของชุดกิจกรรม
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายกิจกรรมในชุด
locationStringสถานที่จัดกิจกรรมในชุด
guestsStringรายชื่ออีเมลที่คั่นด้วยคอมมาซึ่งควรเพิ่ม เป็นผู้เข้าร่วมในกิจกรรมในชุด
sendInvitesBooleanว่าจะส่งอีเมลคำเชิญหรือไม่ (ค่าเริ่มต้น: false)

รีเทิร์น

CalendarEventSeries - กิจกรรมที่สร้างขึ้น

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

getAllCalendars()

รับปฏิทินทั้งหมดที่ผู้ใช้เป็นเจ้าของหรือติดตาม

// Determines how many calendars the user can access.
const calendars = CalendarApp.getAllCalendars();
Logger.log(
    'This user owns or is subscribed to %s calendars.',
    calendars.length,
);

รีเทิร์น

Calendar[] - ปฏิทินทั้งหมดที่ผู้ใช้เข้าถึงได้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getAllOwnedCalendars()

รับปฏิทินทั้งหมดที่ผู้ใช้เป็นเจ้าของ

// Determines how many calendars the user owns.
const calendars = CalendarApp.getAllOwnedCalendars();
Logger.log('This user owns %s calendars.', calendars.length);

รีเทิร์น

Calendar[] - ปฏิทินทั้งหมดที่ผู้ใช้เป็นเจ้าของ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getCalendarById(id)

รับปฏิทินที่มีรหัสที่ระบุ

// Gets the public calendar "US Holidays" by ID.
const calendar = CalendarApp.getCalendarById(
    'en.usa#holiday@group.v.calendar.google.com',
);
Logger.log('The calendar is named "%s".', calendar.getName());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idStringรหัสปฏิทิน

รีเทิร์น

Calendar|null — ปฏิทินที่มีรหัสที่ระบุ หรือ null หากไม่มีปฏิทินดังกล่าว หากผู้ใช้เข้าถึงไม่ได้ หรือหากผู้ใช้ไม่ได้ติดตามปฏิทิน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getCalendarsByName(name)

รับปฏิทินทั้งหมดที่มีชื่อที่ระบุซึ่งผู้ใช้เป็นเจ้าของหรือติดตาม ชื่อไม่คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่

// Gets the public calendar named "US Holidays".
const calendars = CalendarApp.getCalendarsByName('US Holidays');
Logger.log('Found %s matching calendars.', calendars.length);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อปฏิทิน

รีเทิร์น

Calendar[] - ปฏิทินทั้งหมดที่มีชื่อนี้ซึ่งผู้ใช้เข้าถึงได้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getColor()

รับสีของปฏิทิน

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the color of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getColor() instead.
const calendarColor = calendar.getColor();
console.log(calendarColor);

รีเทิร์น

String — สตริงสีแบบเลขฐานสิบหก ("#rrggbb")

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getDefaultCalendar()

รับปฏิทินเริ่มต้นของผู้ใช้

// Determines the time zone of the user's default calendar.
const calendar = CalendarApp.getDefaultCalendar();
Logger.log(
    'My default calendar is set to the time zone "%s".',
    calendar.getTimeZone(),
);

รีเทิร์น

Calendar - ปฏิทินเริ่มต้นของผู้ใช้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getDescription()

รับคำอธิบายของปฏิทิน

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Sets the description of the calendar to 'Test description.'
calendar.setDescription('Test description');

// Gets the description of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getDescription() instead.
const description = calendar.getDescription();
console.log(description);

รีเทิร์น

String — คำอธิบายของปฏิทินนี้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventById(iCalId)

รับกิจกรรมที่มีรหัสที่ระบุ หากชุดข้อมูลเป็นของปฏิทินอื่นที่ไม่ใช่ปฏิทินเริ่มต้น จะต้องเรียกใช้เมธอดนี้จากปฏิทินดังกล่าว การเรียกใช้ getEventById(iCalId) only จะแสดงกิจกรรมในปฏิทินเริ่มต้น

เหตุการณ์หลายรายการอาจมีรหัสเดียวกันหากเป็นส่วนหนึ่งของชุดเหตุการณ์ ในกรณีนี้ เมธอดนี้จะแสดงเฉพาะเหตุการณ์แรกจากชุดเหตุการณ์นั้น

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Creates an event for the moon landing.
const event = calendar.createEvent(
    'Apollo 11 Landing',
    new Date('July 20, 1969 20:05:00 UTC'),
    new Date('July 20, 1969 20:17:00 UTC'),
);

// Gets the calendar event ID and logs it to the console.
const iCalId = event.getId();
console.log(iCalId);

// Gets the event by its ID and logs the title of the event to the console.
// For the default calendar, you can use CalendarApp.getEventById(iCalId)
// instead.
const myEvent = calendar.getEventById(iCalId);
console.log(myEvent.getTitle());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
iCalIdStringรหัสของเหตุการณ์

รีเทิร์น

CalendarEvent — เหตุการณ์ที่มีรหัสที่ระบุ หรือ null หากไม่มีเหตุการณ์หรือผู้ใช้ เข้าถึงไม่ได้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventSeriesById(iCalId)

รับชุดกิจกรรมที่มีรหัสที่ระบุ หากรหัสที่ระบุเป็นของ CalendarEvent รายการเดียว ระบบจะแสดง CalendarEventSeries ที่มีกิจกรรมเดียวในชุด โปรดทราบว่าหากชุดกิจกรรมเป็นของปฏิทินอื่นที่ไม่ใช่ปฏิทินเริ่มต้น คุณต้องเรียกใช้เมธอดนี้จาก CalendarApp นั้น การเรียกใช้ getEventSeriesById(iCalId) โดยตรงจะแสดงเฉพาะชุดกิจกรรมที่มีอยู่ในปฏิทินเริ่มต้น

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Creates an event series for a daily team meeting from 1 PM to 2 PM.
// The series adds the daily event from January 1, 2023 through December 31,
// 2023.
const eventSeries = calendar.createEventSeries(
    'Team meeting',
    new Date('Jan 1, 2023 13:00:00'),
    new Date('Jan 1, 2023 14:00:00'),
    CalendarApp.newRecurrence().addDailyRule().until(new Date('Jan 1, 2024')),
);

// Gets the ID of the event series.
const iCalId = eventSeries.getId();

// Gets the event series by its ID and logs the series title to the console.
// For the default calendar, you can use CalendarApp.getEventSeriesById(iCalId)
// instead.
console.log(calendar.getEventSeriesById(iCalId).getTitle());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
iCalIdStringรหัสของชุดกิจกรรม

รีเทิร์น

CalendarEventSeries — ซีรีส์ที่มีรหัสที่ระบุ หรือ null หากไม่มีซีรีส์หรือผู้ใช้ เข้าถึงไม่ได้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEvents(startTime, endTime)

รับเหตุการณ์ทั้งหมดที่เกิดขึ้นภายในช่วงเวลาที่กำหนด

เมธอดนี้จะแสดงกิจกรรมที่เริ่มต้นในช่วงเวลาที่ระบุ สิ้นสุดในช่วงเวลาที่ระบุ หรือครอบคลุมช่วงเวลาที่ระบุ หากไม่ได้ระบุเขตเวลา ระบบจะตีความค่าเวลาในบริบทของเขตเวลาของสคริปต์ ซึ่งอาจแตกต่างจากเขตเวลาของปฏิทิน

// Determines how many events are happening in the next two hours.
const now = new Date();
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
const events = CalendarApp.getDefaultCalendar().getEvents(now, twoHoursFromNow);
Logger.log(`Number of events: ${events.length}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startTimeDateจุดเริ่มต้นของช่วงเวลา
endTimeDateจุดสิ้นสุดของช่วงเวลา โดยไม่รวมจุดสิ้นสุด

รีเทิร์น

CalendarEvent[] — เหตุการณ์ที่เกิดขึ้นภายในช่วงเวลา

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEvents(startTime, endTime, options)

รับเหตุการณ์ทั้งหมดที่เกิดขึ้นภายในช่วงเวลาที่กำหนดและเป็นไปตามเกณฑ์ที่ระบุ

เมธอดนี้จะแสดงกิจกรรมที่เริ่มต้นในช่วงเวลาที่ระบุ สิ้นสุดในช่วงเวลาที่ระบุ หรือครอบคลุมช่วงเวลาที่ระบุ หากไม่ได้ระบุเขตเวลา ระบบจะตีความค่าเวลาในบริบทของเขตเวลาของสคริปต์ ซึ่งอาจแตกต่างจากเขตเวลาของปฏิทิน

โปรดทราบว่าการกรองใน author, search หรือ statusFilters จะเกิดขึ้นหลังจากใช้ start และ max ซึ่งหมายความว่าจํานวนเหตุการณ์ที่ระบบแสดงอาจน้อยกว่า max แม้ว่าจะมีเหตุการณ์เพิ่มเติมที่ตรงตามเกณฑ์ก็ตาม

// Determines how many events are happening in the next two hours that contain
// the term "meeting".
const now = new Date();
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
const events = CalendarApp.getDefaultCalendar().getEvents(
    now,
    twoHoursFromNow,
    {search: 'meeting'},
);
Logger.log(`Number of events: ${events.length}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
startTimeDateจุดเริ่มต้นของช่วงเวลา
endTimeDateจุดสิ้นสุดของช่วงเวลา โดยไม่รวมจุดสิ้นสุด
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
startIntegerดัชนีของเหตุการณ์แรกที่จะแสดง
maxIntegerจำนวนเหตุการณ์สูงสุดที่จะแสดง
authorStringอีเมลที่ใช้กรองผลลัพธ์ตามผู้สร้างกิจกรรม
searchStringข้อความค้นหาแบบเต็มข้อความที่ใช้กรองผลลัพธ์
statusFilters[]GuestStatusอาร์เรย์ของสถานะที่ใช้กรองผลลัพธ์

รีเทิร์น

CalendarEvent[] - เหตุการณ์ที่เกิดขึ้นภายในช่วงเวลาและตรงกับเกณฑ์

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventsForDay(date)

รับเหตุการณ์ทั้งหมดที่เกิดขึ้นในวันหนึ่งๆ

เมธอดนี้จะแสดงกิจกรรมหากกิจกรรมเริ่มต้นในระหว่างวันนั้น สิ้นสุดในระหว่างวัน หรือ ครอบคลุมวันนั้น

โปรดทราบว่าระบบจะใช้เฉพาะส่วนวันที่ของออบเจ็กต์ Date และจะเพิกเฉยต่อส่วนเวลา ระบบจะตีความวันที่เป็นตั้งแต่เที่ยงคืนของวันนั้นจนถึงเที่ยงคืนของวันถัดไปในเขตเวลาของปฏิทิน

// Determines how many events are happening today.
const today = new Date();
const events = CalendarApp.getDefaultCalendar().getEventsForDay(today);
Logger.log(`Number of events: ${events.length}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateDateวันที่ที่จะดึงเหตุการณ์ (ใช้เฉพาะวัน ส่วนเวลาจะถูกละเว้น)

รีเทิร์น

CalendarEvent[] — เหตุการณ์ที่เกิดขึ้นในวันที่ที่ระบุ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getEventsForDay(date, options)

รับเหตุการณ์ทั้งหมดที่เกิดขึ้นในวันที่ระบุและตรงตามเกณฑ์ที่ระบุ

เมธอดนี้จะแสดงกิจกรรมหากกิจกรรมเริ่มต้นในระหว่างวันนั้น สิ้นสุดในระหว่างวัน หรือ ครอบคลุมวันนั้น

โปรดทราบว่าระบบจะใช้เฉพาะส่วนวันที่ของออบเจ็กต์ Date และจะเพิกเฉยต่อส่วนเวลา ระบบจะตีความวันที่เป็นตั้งแต่เที่ยงคืนของวันนั้นจนถึงเที่ยงคืนของวันถัดไปในเขตเวลาของปฏิทิน

โปรดทราบว่าการกรองใน author, search หรือ statusFilters จะเกิดขึ้นหลังจากใช้ start และ max ซึ่งหมายความว่าจํานวนเหตุการณ์ที่ระบบแสดงอาจน้อยกว่า max แม้ว่าจะมีเหตุการณ์เพิ่มเติมที่ตรงตามเกณฑ์ก็ตาม

// Determines how many events are happening today and contain the term
// "meeting".
const today = new Date();
const events = CalendarApp.getDefaultCalendar().getEventsForDay(today, {
  search: 'meeting',
});
Logger.log(`Number of events: ${events.length}`);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
dateDateวันที่ที่จะดึงเหตุการณ์ (ใช้เฉพาะวัน ส่วนเวลาจะถูกละเว้น)
optionsObjectตัวเลือกการกรองขั้นสูง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
startIntegerดัชนีของเหตุการณ์แรกที่จะแสดง
maxIntegerจำนวนเหตุการณ์สูงสุดที่จะแสดง
authorStringอีเมลที่ใช้กรองผลลัพธ์ตามผู้สร้างกิจกรรม
searchStringข้อความค้นหาแบบเต็มข้อความที่ใช้กรองผลลัพธ์
statusFilters[]GuestStatusอาร์เรย์ของสถานะที่ใช้กรองผลลัพธ์

รีเทิร์น

CalendarEvent[] - เหตุการณ์ที่เกิดขึ้นในวันที่ระบุและตรงกับเกณฑ์

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getId()

รับรหัสของปฏิทิน รหัสสำหรับปฏิทินเริ่มต้นของผู้ใช้คืออีเมลของผู้ใช้

// Opens the calendar by its ID.
// To get the user's default calendar, use CalendarApp.getDefaultCalendar().
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the ID of the calendar and logs it to the console.
const calendarId = calendar.getId();
console.log(calendarId);

รีเทิร์น

String — รหัสของปฏิทิน

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getName()

รับชื่อปฏิทิน

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the name of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getName() instead.
const calendarName = calendar.getName();
console.log(calendarName);

รีเทิร์น

String — ชื่อปฏิทินนี้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getOwnedCalendarById(id)

รับปฏิทินที่มีรหัสที่ระบุ หากผู้ใช้เป็นเจ้าของ

หากต้องการค้นหารหัสปฏิทิน ให้คลิกลูกศรข้างชื่อปฏิทินใน Google ปฏิทิน แล้วเลือกการตั้งค่าปฏิทิน รหัสจะแสดงที่ด้านล่างของหน้าการตั้งค่า

// Gets a (non-existent) private calendar by ID.
const calendar = CalendarApp.getOwnedCalendarById(
    '123456789@group.calendar.google.com',
);
Logger.log('The calendar is named "%s".', calendar.getName());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idStringรหัสปฏิทิน

รีเทิร์น

Calendar|null - ปฏิทินที่มีรหัสที่ระบุ หรือ null หากไม่มีปฏิทินหรือ ผู้ใช้ไม่ได้เป็นเจ้าของ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getOwnedCalendarsByName(name)

รับปฏิทินทั้งหมดที่มีชื่อที่ระบุซึ่งผู้ใช้เป็นเจ้าของ ชื่อไม่คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่

// Gets a private calendar named "Travel Plans".
const calendars = CalendarApp.getOwnedCalendarsByName('Travel Plans');
Logger.log('Found %s matching calendars.', calendars.length);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อปฏิทิน

รีเทิร์น

Calendar[] — ปฏิทินทั้งหมดที่มีชื่อนี้ซึ่งผู้ใช้เป็นเจ้าของ

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

getTimeZone()

รับเขตเวลาของปฏิทิน

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Gets the time zone of the calendar and logs it to the console.
// For the default calendar, you can use CalendarApp.getTimeZone() instead.
const timeZone = calendar.getTimeZone();
console.log(timeZone);

รีเทิร์น

String — เขตเวลาที่ระบุในรูปแบบ "ยาว" (เช่น "America/New_York" ตามที่แสดงใน Joda.org)

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isHidden()

กำหนดว่าจะซ่อนปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Determines whether the calendar is hidden in the user interface and logs it
// to the console. For the default calendar, you can use CalendarApp.isHidden()
// instead.
const isHidden = calendar.isHidden();
console.log(isHidden);

รีเทิร์น

Booleantrue หากปฏิทินซ่อนอยู่ในอินเทอร์เฟซผู้ใช้ false หากปฏิทินไม่ซ่อนอยู่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isMyPrimaryCalendar()

กำหนดว่าปฏิทินเป็นปฏิทินหลักสำหรับผู้ใช้ที่มีผลหรือไม่

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Determines whether the calendar is the default calendar for
// the effective user and logs it to the console.
// For the default calendar, you can use CalendarApp.isMyPrimaryCalendar()
// instead.
const isMyPrimaryCalendar = calendar.isMyPrimaryCalendar();
console.log(isMyPrimaryCalendar);

รีเทิร์น

Booleantrue หากปฏิทินเป็นปฏิทินเริ่มต้นสำหรับผู้ใช้ที่มีผล false หากไม่ใช่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isOwnedByMe()

ระบุว่าคุณเป็นเจ้าของปฏิทินหรือไม่

// Gets a calendar by its ID. To get the user's default calendar, use
// CalendarApp.getDefault() instead.
// TODO(developer): Replace the ID with the calendar ID that you want to use.
const calendar = CalendarApp.getCalendarById(
    'abc123456@group.calendar.google.com',
);

// Determines whether the calendar is owned by you and logs it.
console.log(calendar.isOwnedByMe());

รีเทิร์น

Booleantrue หากคุณเป็นเจ้าของปฏิทิน false หากไม่ใช่

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

isSelected()

กำหนดว่าจะแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่

// Gets the user's default calendar. To get a different calendar,
// use getCalendarById() instead.
const calendar = CalendarApp.getDefaultCalendar();

// Determines whether the calendar's events are displayed in the user interface
// and logs it.
console.log(calendar.isSelected());

รีเทิร์น

Booleantrue หากกิจกรรมของปฏิทินแสดงในอินเทอร์เฟซผู้ใช้ false หากไม่แสดง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

newRecurrence()

สร้างออบเจ็กต์การเกิดซ้ำใหม่ ซึ่งใช้สร้างกฎสำหรับการเกิดซ้ำของเหตุการณ์ได้

// Creates an event series for a no-meetings day, taking place every Wednesday
// in 2013.
const recurrence = CalendarApp.newRecurrence()
                       .addWeeklyRule()
                       .onlyOnWeekday(CalendarApp.Weekday.WEDNESDAY)
                       .until(new Date('January 1, 2014'));
const eventSeries = CalendarApp.getDefaultCalendar().createAllDayEventSeries(
    'No Meetings',
    new Date('January 2, 2013 03:00:00 PM EST'),
    recurrence,
);
Logger.log(`Event Series ID: ${eventSeries.getId()}`);

รีเทิร์น

EventRecurrence - ออบเจ็กต์การเกิดซ้ำใหม่ที่ไม่มีการตั้งกฎ (ทำงานเป็นการเกิดซ้ำรายสัปดาห์)

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.googleapis.com/auth/calendar.readonly
  • https://www.google.com/calendar/feeds

setColor(color)

ตั้งค่าสีของปฏิทิน

// Opens the calendar by its ID.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById('222larabrown@gmail.com');

// Sets the color of the calendar to pink using the Calendar Color enum.
// For the default calendar, you can use CalendarApp.setColor() instead.
calendar.setColor(CalendarApp.Color.PINK);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
colorStringCalendarApp.Color หรือสตริงสีแบบเลขฐานสิบหก ("#rrggbb")

รีเทิร์น

Calendar — ปฏิทินนี้สำหรับการเชื่อมโยง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setDescription(description)

ตั้งค่าคำอธิบายของปฏิทิน

// Gets the user's default calendar. To get a different calendar,
// use getCalendarById() instead.
const calendar = CalendarApp.getDefaultCalendar();

// Sets the description of the calendar.
// TODO(developer): Update the string with the description that you want to use.
calendar.setDescription('Updated calendar description.');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
descriptionStringคำอธิบายของปฏิทินนี้

รีเทิร์น

Calendar - ปฏิทินนี้สำหรับการเชื่อมโยง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setHidden(hidden)

กำหนดว่าจะให้ปฏิทินปรากฏในอินเทอร์เฟซผู้ใช้หรือไม่

พารามิเตอร์

ชื่อประเภทคำอธิบาย
hiddenBooleantrue เพื่อซ่อนปฏิทินในอินเทอร์เฟซผู้ใช้ false เพื่อแสดงปฏิทิน

รีเทิร์น

Calendar - ปฏิทินนี้สำหรับการเชื่อมโยง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setName(name)

ตั้งชื่อปฏิทิน

// Gets the user's default calendar. To get a different calendar,
// use getCalendarById() instead.
const calendar = CalendarApp.getDefaultCalendar();

// Sets the name of the calendar.
// TODO(developer): Update the string with the name that you want to use.
calendar.setName('Example calendar name');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
nameStringชื่อใหม่

รีเทิร์น

Calendar - ปฏิทินนี้สำหรับการเชื่อมโยง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setSelected(selected)

กำหนดว่าจะแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่

// Gets the user's default calendar. To get a different calendar,
// use getCalendarById() instead.
const calendar = CalendarApp.getDefaultCalendar();

// Selects the calendar so that its events are displayed in the user interface.
// To unselect the calendar, set the parameter to false.
calendar.setSelected(true);

พารามิเตอร์

ชื่อประเภทคำอธิบาย
selectedBooleantrue เพื่อแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้ false เพื่อซ่อนกิจกรรม

รีเทิร์น

Calendar - ปฏิทินนี้สำหรับการเชื่อมโยง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

setTimeZone(timeZone)

ตั้งค่าเขตเวลาของปฏิทิน

// Gets the user's default calendar. To get a different calendar,
// use getCalendarById() instead.
const calendar = CalendarApp.getDefaultCalendar();

// Sets the time zone of the calendar to America/New York (US/Eastern) time.
calendar.setTimeZone('America/New_York');

พารามิเตอร์

ชื่อประเภทคำอธิบาย
timeZoneStringเขตเวลาที่ระบุในรูปแบบ "ยาว" (เช่น "America/New_York" ตามที่ระบุโดย Joda.org)

รีเทิร์น

Calendar — ปฏิทินนี้สำหรับการเชื่อมโยง

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

subscribeToCalendar(id)

ติดตามปฏิทินของผู้ใช้ด้วยรหัสที่ระบุ หากผู้ใช้ได้รับอนุญาตให้ติดตาม

// Subscribe to the calendar "US Holidays".
const calendar = CalendarApp.subscribeToCalendar(
    'en.usa#holiday@group.v.calendar.google.com',
);
Logger.log('Subscribed to the calendar "%s".', calendar.getName());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idStringรหัสของปฏิทินที่จะติดตาม

รีเทิร์น

Calendar - ปฏิทินที่เพิ่งสมัครรับข้อมูล

ส่ง

Error — หากไม่มีปฏิทินที่มีรหัสนี้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds

subscribeToCalendar(id, options)

ติดตามปฏิทินของผู้ใช้ด้วยรหัสที่ระบุ หากผู้ใช้ได้รับอนุญาตให้ติดตาม

// Subscribe to the calendar "US Holidays", and set it to the color blue.
const calendar = CalendarApp.subscribeToCalendar(
    'en.usa#holiday@group.v.calendar.google.com',
    {color: CalendarApp.Color.BLUE},
);
Logger.log('Subscribed to the calendar "%s".', calendar.getName());

พารามิเตอร์

ชื่อประเภทคำอธิบาย
idStringรหัสของปฏิทินที่จะติดตาม
optionsObjectออบเจ็กต์ JavaScript ที่ระบุพารามิเตอร์ขั้นสูงตามที่ระบุไว้ด้านล่าง

พารามิเตอร์ขั้นสูง

ชื่อประเภทคำอธิบาย
colorStringสตริงสีแบบเลขฐานสิบหก ("#rrggbb") หรือค่าจาก CalendarApp.Colors
hiddenBooleanดูว่าปฏิทินซ่อนอยู่ในอินเทอร์เฟซผู้ใช้หรือไม่ (ค่าเริ่มต้น: false)
selectedBooleanว่าจะแสดงกิจกรรมของปฏิทินในอินเทอร์เฟซผู้ใช้หรือไม่ (ค่าเริ่มต้น: true หากระบุ color ด้วย false มิฉะนั้น)

รีเทิร์น

Calendar — ปฏิทินที่เพิ่งติดตาม

ส่ง

Error — หากไม่มีปฏิทินที่มีรหัสนี้

การให้สิทธิ์

สคริปต์ที่ใช้วิธีนี้ต้องมีการให้สิทธิ์ที่มีขอบเขตต่อไปนี้อย่างน้อย 1 รายการ หรือขอบเขตที่เหมาะสมจาก REST API ที่เกี่ยวข้อง

  • https://www.googleapis.com/auth/calendar
  • https://www.google.com/calendar/feeds