สร้างกิจกรรม ลองใช้เลยหรือดูตัวอย่าง
ส่งคำขอ
คำขอ HTTP
POST https://www.googleapis.com/calendar/v3/calendars/calendarId/events
พารามิเตอร์
ชื่อพารามิเตอร์ | ค่า | คำอธิบาย |
---|---|---|
พารามิเตอร์เส้นทาง | ||
calendarId |
string |
ตัวระบุปฏิทิน ในการเรียกรหัสปฏิทินให้เรียกใช้เมธอด calendarList.list หากต้องการเข้าถึงปฏิทินหลักของผู้ใช้ที่เข้าสู่ระบบในปัจจุบัน ให้ใช้คีย์เวิร์ด "primary "
|
พารามิเตอร์การค้นหาที่ไม่บังคับ | ||
conferenceDataVersion |
integer |
หมายเลขเวอร์ชันของข้อมูลการประชุมที่ไคลเอ็นต์ API รองรับ เวอร์ชัน 0 ถือว่าไม่มีการสนับสนุนข้อมูลการประชุม และไม่สนใจข้อมูลการประชุมในเนื้อหาของกิจกรรม เวอร์ชัน 1 ช่วยให้สามารถคัดลอก ConeData และสามารถสร้างการประชุมใหม่โดยใช้ช่อง createRequest ของ meetData ค่าเริ่มต้นคือ 0
ค่าที่ยอมรับได้คือ 0 ถึง 1
|
maxAttendees |
integer |
จำนวนผู้เข้าร่วมสูงสุดที่จะรวมในการตอบกลับ หากมีผู้เข้าร่วมเกินจำนวนที่ระบุ ระบบจะแสดงผลเฉพาะผู้เข้าร่วมเท่านั้น ไม่บังคับ |
sendNotifications |
boolean |
เลิกใช้งานแล้ว โปรดใช้ sendUpdates แทน ต้องการส่งการแจ้งเตือนเกี่ยวกับการสร้างกิจกรรมใหม่ไหม โปรดทราบว่าระบบอาจยังส่งอีเมลบางรายการแม้ว่าคุณจะกำหนดค่าเป็น false ก็ตาม โดยมีค่าเริ่มต้นเป็น false
|
sendUpdates |
string |
จะส่งการแจ้งเตือนเกี่ยวกับการสร้างกิจกรรมใหม่หรือไม่ โปรดทราบว่าระบบอาจยังส่งอีเมลบางรายการได้อยู่ โดยมีค่าเริ่มต้นเป็น false
ค่าที่ยอมรับมีดังนี้
|
supportsAttachments |
boolean |
การทำงานของไคลเอ็นต์ API จะรองรับไฟล์แนบเหตุการณ์หรือไม่ ไม่บังคับ ทั้งนี้ ระบบตั้งค่าเริ่มต้นไว้เป็น "เท็จ" |
การให้สิทธิ์
คำขอนี้ต้องได้รับสิทธิ์โดยมีขอบเขตต่อไปนี้อย่างน้อย 1 ขอบเขต
ขอบเขต |
---|
https://www.googleapis.com/auth/calendar |
https://www.googleapis.com/auth/calendar.events |
ดูข้อมูลเพิ่มเติมได้ที่หน้าการตรวจสอบสิทธิ์และการให้สิทธิ์
เนื้อหาของคำขอ
ในเนื้อหาคำขอ ให้ระบุทรัพยากรเหตุการณ์พร้อมด้วยพร็อพเพอร์ตี้ต่อไปนี้
ชื่อพร็อพเพอร์ตี้ | ค่า | คำอธิบาย | Notes |
---|---|---|---|
พร็อพเพอร์ตี้ที่จำเป็น | |||
end |
nested object |
เวลาสิ้นสุด (เฉพาะตัว) ของกิจกรรม สำหรับกิจกรรมที่เกิดซ้ำ เวลานี้จะเป็นการสิ้นสุดของอินสแตนซ์แรก | |
start |
nested object |
เวลาเริ่มต้น (รวม) ของกิจกรรม สำหรับกิจกรรมที่เกิดซ้ำ นี่คือเวลาเริ่มต้นของอินสแตนซ์แรก | |
พร็อพเพอร์ตี้ที่ไม่บังคับ | |||
anyoneCanAddSelf |
boolean |
ทุกคนสามารถเชิญตนเองเข้าร่วมกิจกรรมได้หรือไม่ (เลิกใช้งานแล้ว) ไม่บังคับ ทั้งนี้ ระบบตั้งค่าเริ่มต้นไว้เป็น "เท็จ" | เขียนได้ |
attachments[].fileUrl |
string |
URL ของไฟล์แนบ สำหรับการเพิ่มไฟล์แนบของ Google ไดรฟ์ ให้ใช้รูปแบบเดียวกับในพร็อพเพอร์ตี้ ต้องระบุเมื่อเพิ่มไฟล์แนบ |
เขียนได้ |
attendees[] |
list |
ผู้เข้าร่วมกิจกรรม โปรดดูคู่มือกิจกรรมที่มีผู้เข้าร่วมเพื่อดูข้อมูลเพิ่มเติมเกี่ยวกับการกำหนดเวลากิจกรรมกับผู้ใช้ปฏิทินคนอื่นๆ บัญชีบริการต้องใช้การมอบสิทธิ์ทั่วทั้งโดเมนเพื่อเติมข้อมูลรายชื่อผู้เข้าร่วม | เขียนได้ |
attendees[].additionalGuests |
integer |
จำนวนแขกที่เข้าพักเพิ่มเติม ไม่บังคับ ค่าเริ่มต้นคือ 0 | เขียนได้ |
attendees[].comment |
string |
ความคิดเห็นตอบกลับของผู้เข้าร่วม ไม่บังคับ | เขียนได้ |
attendees[].displayName |
string |
ชื่อผู้เข้าร่วม (หากมี) ไม่บังคับ | เขียนได้ |
attendees[].email |
string |
อีเมลของผู้เข้าร่วม (หากมี) ต้องมีช่องนี้เมื่อเพิ่มผู้เข้าร่วม ต้องเป็นอีเมลที่ถูกต้องตาม RFC5322 ต้องระบุเมื่อเพิ่มผู้เข้าร่วม |
เขียนได้ |
attendees[].optional |
boolean |
ผู้เข้าร่วมรายนี้เป็นผู้เข้าร่วมที่ไม่บังคับใช่หรือไม่ ไม่บังคับ ทั้งนี้ ระบบตั้งค่าเริ่มต้นไว้เป็น "เท็จ" | เขียนได้ |
attendees[].resource |
boolean |
ผู้เข้าร่วมเป็นทรัพยากรหรือไม่ สามารถตั้งค่าได้เมื่อมีการเพิ่มผู้เข้าร่วมในกิจกรรมเป็นครั้งแรกเท่านั้น ระบบจะไม่สนใจการแก้ไขหลังจากนั้น ไม่บังคับ ทั้งนี้ ระบบตั้งค่าเริ่มต้นไว้เป็น "เท็จ" | เขียนได้ |
attendees[].responseStatus |
string |
สถานะการตอบกลับของผู้เข้าร่วม ค่าที่เป็นไปได้มีดังนี้:
|
เขียนได้ |
colorId |
string |
สีของกิจกรรม นี่คือรหัสที่อ้างถึงรายการในส่วน event ของคำจำกัดความสี (ดู ปลายทางสี) ไม่บังคับ |
เขียนได้ |
conferenceData |
nested object |
ข้อมูลเกี่ยวกับการประชุม เช่น รายละเอียดการประชุมของ Google Meet หากต้องการสร้างรายละเอียดการประชุมใหม่ ให้ใช้ช่อง createRequest หากต้องการคงการเปลี่ยนแปลงไว้ อย่าลืมตั้งค่าพารามิเตอร์คำขอ conferenceDataVersion เป็น 1 สำหรับคำขอแก้ไขเหตุการณ์ทั้งหมด |
เขียนได้ |
description |
string |
คำอธิบายกิจกรรม มี HTML ได้ ไม่บังคับ | เขียนได้ |
end.date |
date |
วันที่ในรูปแบบ "yyyy-mm-dd" หากเป็นกิจกรรมที่จัดขึ้นทั้งวัน | เขียนได้ |
end.dateTime |
datetime |
เวลาเป็นค่าวันที่และเวลาแบบรวม (จัดรูปแบบตาม RFC3339) จำเป็นต้องมีการชดเชยเขตเวลา เว้นแต่จะมีการระบุเขตเวลาเป็น timeZone อย่างชัดเจน |
เขียนได้ |
end.timeZone |
string |
เขตเวลาที่ระบุเวลา (จัดรูปแบบเป็นชื่อฐานข้อมูลเขตเวลา IANA เช่น "ยุโรป/ซูริก") สำหรับกิจกรรมที่เกิดซ้ำ ฟิลด์นี้ต้องระบุและระบุเขตเวลาที่มีการขยายการเกิดซ้ำ สำหรับเหตุการณ์เดียว ช่องนี้จะระบุหรือไม่ก็ได้ และจะระบุเขตเวลาที่กำหนดเองสำหรับจุดเริ่มต้น/สิ้นสุดกิจกรรม | เขียนได้ |
eventType |
string |
ประเภทเหตุการณ์ที่เจาะจง เมื่อสร้างเหตุการณ์แล้วจะแก้ไขไม่ได้ ค่าที่เป็นไปได้มีดังนี้:
|
เขียนได้ |
extendedProperties.private |
object |
พร็อพเพอร์ตี้ที่เป็นแบบส่วนตัวสำหรับสำเนาของกิจกรรมที่ปรากฏในปฏิทินนี้ | เขียนได้ |
extendedProperties.shared |
object |
พร็อพเพอร์ตี้ที่แชร์ระหว่างสำเนากิจกรรมในปฏิทินของผู้เข้าร่วมรายอื่น | เขียนได้ |
focusTimeProperties |
nested object |
ข้อมูลเหตุการณ์ที่ต้องการสมาธิ ใช้เมื่อ eventType คือ focusTime |
เขียนได้ |
gadget.display |
string |
โหมดการแสดงผลของแกดเจ็ต เลิกใช้งานแล้ว ค่าที่เป็นไปได้มีดังนี้:
|
เขียนได้ |
gadget.height |
integer |
ความสูงของแกดเจ็ต หน่วยเป็นพิกเซล ความสูงต้องเป็นจำนวนเต็มที่มากกว่า 0 ไม่บังคับ เลิกใช้งานแล้ว | เขียนได้ |
gadget.iconLink |
string |
URL ไอคอนของแกดเจ็ต Scheme ของ URL ต้องเป็น HTTPS เลิกใช้งานแล้ว | เขียนได้ |
gadget.link |
string |
URL ของแกดเจ็ต Scheme ของ URL ต้องเป็น HTTPS เลิกใช้งานแล้ว | เขียนได้ |
gadget.preferences |
object |
ค่ากำหนด | เขียนได้ |
gadget.title |
string |
ชื่อแกดเจ็ต เลิกใช้งานแล้ว | เขียนได้ |
gadget.type |
string |
ประเภทของแกดเจ็ต เลิกใช้งานแล้ว | เขียนได้ |
gadget.width |
integer |
ความกว้างของแกดเจ็ตเป็นพิกเซล ความกว้างต้องเป็นจำนวนเต็มที่มากกว่า 0 ไม่บังคับ เลิกใช้งานแล้ว | เขียนได้ |
guestsCanInviteOthers |
boolean |
ผู้เข้าร่วมนอกเหนือจากผู้จัดสามารถเชิญผู้อื่นเข้าร่วมกิจกรรมได้หรือไม่ ไม่บังคับ ค่าเริ่มต้นคือ "จริง" | เขียนได้ |
guestsCanModify |
boolean |
ผู้เข้าร่วมนอกเหนือจากผู้จัดจะแก้ไขกิจกรรมได้หรือไม่ ไม่บังคับ ทั้งนี้ ระบบตั้งค่าเริ่มต้นไว้เป็น "เท็จ" | เขียนได้ |
guestsCanSeeOtherGuests |
boolean |
ผู้เข้าร่วมนอกเหนือจากผู้จัดสามารถดูได้ว่าผู้เข้าร่วมกิจกรรมเป็นใคร ไม่บังคับ ค่าเริ่มต้นคือ "จริง" | เขียนได้ |
id |
string |
ตัวระบุเหตุการณ์แบบทึบ เวลาสร้างกิจกรรมรายการเดียวหรือกิจกรรมที่เกิดซ้ำ คุณสามารถระบุรหัสได้ รหัสที่ระบุต้องเป็นไปตามกฎต่อไปนี้
หากคุณไม่ระบุ ID เซิร์ฟเวอร์จะสร้างให้โดยอัตโนมัติ โปรดทราบว่า |
เขียนได้ |
location |
string |
สถานที่ตั้งทางภูมิศาสตร์ของกิจกรรมแบบข้อความรูปแบบอิสระ ไม่บังคับ | เขียนได้ |
originalStartTime.date |
date |
วันที่ในรูปแบบ "yyyy-mm-dd" หากเป็นกิจกรรมที่จัดขึ้นทั้งวัน | เขียนได้ |
originalStartTime.dateTime |
datetime |
เวลาเป็นค่าวันที่และเวลาแบบรวม (จัดรูปแบบตาม RFC3339) จำเป็นต้องมีการชดเชยเขตเวลา เว้นแต่จะมีการระบุเขตเวลาเป็น timeZone อย่างชัดเจน |
เขียนได้ |
originalStartTime.timeZone |
string |
เขตเวลาที่ระบุเวลา (จัดรูปแบบเป็นชื่อฐานข้อมูลเขตเวลา IANA เช่น "ยุโรป/ซูริก") สำหรับกิจกรรมที่เกิดซ้ำ ฟิลด์นี้ต้องระบุและระบุเขตเวลาที่มีการขยายการเกิดซ้ำ สำหรับเหตุการณ์เดียว ช่องนี้จะระบุหรือไม่ก็ได้ และจะระบุเขตเวลาที่กำหนดเองสำหรับจุดเริ่มต้น/สิ้นสุดกิจกรรม | เขียนได้ |
outOfOfficeProperties |
nested object |
ข้อมูลกิจกรรมลางาน ใช้เมื่อ eventType คือ outOfOffice |
เขียนได้ |
recurrence[] |
list |
รายการบรรทัด RRULE, EXRULE, RDATE และ EXDATE สำหรับกิจกรรมที่เกิดซ้ำ ตามที่ระบุไว้ใน RFC5545 โปรดทราบว่าไม่อนุญาตให้ใช้บรรทัด DTSTART และ DTEND ในช่องนี้ เนื่องจากมีการระบุเวลาเริ่มต้นและสิ้นสุดของกิจกรรมในช่อง start และ end ช่องนี้จะถูกละไว้สำหรับกิจกรรมเดี่ยวหรือกิจกรรมที่เกิดซ้ำ |
เขียนได้ |
reminders.overrides[] |
list |
หากกิจกรรมไม่ได้ใช้การแจ้งเตือนเริ่มต้น ระบบจะแสดงการแจ้งเตือนสำหรับกิจกรรมดังกล่าวเท่านั้น หรือหากไม่ได้ตั้งค่า แสดงว่าไม่มีการตั้งค่าการแจ้งเตือนสำหรับกิจกรรมนี้ จำนวนการแจ้งเตือนให้ลบล้างสูงสุดคือ 5 ครั้ง | เขียนได้ |
reminders.overrides[].method |
string |
วิธีการที่การช่วยเตือนนี้ใช้ ค่าที่เป็นไปได้มีดังนี้:
ต้องระบุเมื่อเพิ่มการช่วยเตือน |
เขียนได้ |
reminders.overrides[].minutes |
integer |
จำนวนนาทีก่อนกิจกรรมจะเริ่มเมื่อการช่วยเตือนควรทริกเกอร์ ค่าที่ใช้ได้จะอยู่ระหว่าง 0 ถึง 40320 (4 สัปดาห์ในหน่วยนาที) ต้องระบุเมื่อเพิ่มการช่วยเตือน |
เขียนได้ |
reminders.useDefault |
boolean |
จะใช้การช่วยเตือนเริ่มต้นของปฏิทินกับกิจกรรมหรือไม่ | เขียนได้ |
sequence |
integer |
หมายเลขลำดับตาม iCalendar | เขียนได้ |
source.title |
string |
ชื่อของแหล่งที่มา เช่น ชื่อของหน้าเว็บหรือเรื่องของอีเมล | เขียนได้ |
source.url |
string |
URL ของแหล่งที่มาที่ชี้ไปยังแหล่งข้อมูล Scheme ของ URL ต้องเป็น HTTP หรือ HTTPS | เขียนได้ |
start.date |
date |
วันที่ในรูปแบบ "yyyy-mm-dd" หากเป็นกิจกรรมที่จัดขึ้นทั้งวัน | เขียนได้ |
start.dateTime |
datetime |
เวลาเป็นค่าวันที่และเวลาแบบรวม (จัดรูปแบบตาม RFC3339) จำเป็นต้องมีการชดเชยเขตเวลา เว้นแต่จะมีการระบุเขตเวลาเป็น timeZone อย่างชัดเจน |
เขียนได้ |
start.timeZone |
string |
เขตเวลาที่ระบุเวลา (จัดรูปแบบเป็นชื่อฐานข้อมูลเขตเวลา IANA เช่น "ยุโรป/ซูริก") สำหรับกิจกรรมที่เกิดซ้ำ ฟิลด์นี้ต้องระบุและระบุเขตเวลาที่มีการขยายการเกิดซ้ำ สำหรับเหตุการณ์เดียว ช่องนี้จะระบุหรือไม่ก็ได้ และจะระบุเขตเวลาที่กำหนดเองสำหรับจุดเริ่มต้น/สิ้นสุดกิจกรรม | เขียนได้ |
status |
string |
สถานะของเหตุการณ์ ไม่บังคับ ค่าที่เป็นไปได้มีดังนี้:
|
เขียนได้ |
summary |
string |
ชื่อกิจกรรม | เขียนได้ |
transparency |
string |
กิจกรรมจะบล็อกเวลาในปฏิทินหรือไม่ ไม่บังคับ ค่าที่เป็นไปได้มีดังนี้:
|
เขียนได้ |
visibility |
string |
ระดับการเข้าถึงกิจกรรม ไม่บังคับ ค่าที่เป็นไปได้มีดังนี้:
|
เขียนได้ |
workingLocationProperties |
nested object |
ข้อมูลเหตุการณ์สถานที่ทำงาน | เขียนได้ |
workingLocationProperties.customLocation |
object |
หากมี ให้ระบุว่าผู้ใช้ทำงานจากสถานที่ที่กำหนดเอง | เขียนได้ |
workingLocationProperties.customLocation.label |
string |
ป้ายกำกับเพิ่มเติมซึ่งไม่บังคับสำหรับข้อมูลเพิ่มเติม | เขียนได้ |
workingLocationProperties.homeOffice |
any value |
หากมี ให้ระบุว่าผู้ใช้กำลังทำงานที่บ้าน | เขียนได้ |
workingLocationProperties.officeLocation |
object |
หากมี ให้ระบุว่าผู้ใช้ทำงานจากสำนักงาน | เขียนได้ |
workingLocationProperties.officeLocation.buildingId |
string |
ตัวระบุอาคารที่ไม่บังคับ ซึ่งควรอ้างอิงรหัสอาคารในฐานข้อมูลทรัพยากรขององค์กร | เขียนได้ |
workingLocationProperties.officeLocation.deskId |
string |
ตัวระบุเดสก์ (ไม่บังคับ) | เขียนได้ |
workingLocationProperties.officeLocation.floorId |
string |
ตัวระบุชั้นที่ไม่บังคับ | เขียนได้ |
workingLocationProperties.officeLocation.floorSectionId |
string |
ตัวระบุส่วนชั้นที่ไม่บังคับ | เขียนได้ |
workingLocationProperties.officeLocation.label |
string |
ชื่อสำนักงานที่แสดงในไคลเอ็นต์ของปฏิทินบนเว็บและอุปกรณ์เคลื่อนที่ เราขอแนะนำให้คุณอ้างอิงชื่ออาคารในฐานข้อมูลทรัพยากรขององค์กร | เขียนได้ |
workingLocationProperties.type |
string |
ประเภทสถานที่ทำงาน ค่าที่เป็นไปได้มีดังนี้:
ต้องระบุเมื่อเพิ่มพร็อพเพอร์ตี้สถานที่ทำงาน |
เขียนได้ |
คำตอบ
หากสําเร็จ เมธอดนี้จะแสดงทรัพยากรเหตุการณ์ในเนื้อหาการตอบสนอง
ตัวอย่าง
หมายเหตุ: ตัวอย่างโค้ดที่มีสำหรับวิธีการนี้ไม่ได้แสดงถึงภาษาโปรแกรมที่รองรับทั้งหมด (ดูรายการภาษาที่รองรับได้ในหน้าไลบรารีของไคลเอ็นต์)
Java
// Refer to the Java quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/java // Change the scope to CalendarScopes.CALENDAR and delete any stored // credentials. Event event = new Event() .setSummary("Google I/O 2015") .setLocation("800 Howard St., San Francisco, CA 94103") .setDescription("A chance to hear more about Google's developer products."); DateTime startDateTime = new DateTime("2015-05-28T09:00:00-07:00"); EventDateTime start = new EventDateTime() .setDateTime(startDateTime) .setTimeZone("America/Los_Angeles"); event.setStart(start); DateTime endDateTime = new DateTime("2015-05-28T17:00:00-07:00"); EventDateTime end = new EventDateTime() .setDateTime(endDateTime) .setTimeZone("America/Los_Angeles"); event.setEnd(end); String[] recurrence = new String[] {"RRULE:FREQ=DAILY;COUNT=2"}; event.setRecurrence(Arrays.asList(recurrence)); EventAttendee[] attendees = new EventAttendee[] { new EventAttendee().setEmail("lpage@example.com"), new EventAttendee().setEmail("sbrin@example.com"), }; event.setAttendees(Arrays.asList(attendees)); EventReminder[] reminderOverrides = new EventReminder[] { new EventReminder().setMethod("email").setMinutes(24 * 60), new EventReminder().setMethod("popup").setMinutes(10), }; Event.Reminders reminders = new Event.Reminders() .setUseDefault(false) .setOverrides(Arrays.asList(reminderOverrides)); event.setReminders(reminders); String calendarId = "primary"; event = service.events().insert(calendarId, event).execute(); System.out.printf("Event created: %s\n", event.getHtmlLink());
Python
# Refer to the Python quickstart on how to setup the environment: # https://developers.google.com/calendar/quickstart/python # Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any # stored credentials. event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': 'lpage@example.com'}, {'email': 'sbrin@example.com'}, ], 'reminders': { 'useDefault': False, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10}, ], }, } event = service.events().insert(calendarId='primary', body=event).execute() print 'Event created: %s' % (event.get('htmlLink'))
PHP
// Refer to the PHP quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/php // Change the scope to Google_Service_Calendar::CALENDAR and delete any stored // credentials. $event = new Google_Service_Calendar_Event(array( 'summary' => 'Google I/O 2015', 'location' => '800 Howard St., San Francisco, CA 94103', 'description' => 'A chance to hear more about Google\'s developer products.', 'start' => array( 'dateTime' => '2015-05-28T09:00:00-07:00', 'timeZone' => 'America/Los_Angeles', ), 'end' => array( 'dateTime' => '2015-05-28T17:00:00-07:00', 'timeZone' => 'America/Los_Angeles', ), 'recurrence' => array( 'RRULE:FREQ=DAILY;COUNT=2' ), 'attendees' => array( array('email' => 'lpage@example.com'), array('email' => 'sbrin@example.com'), ), 'reminders' => array( 'useDefault' => FALSE, 'overrides' => array( array('method' => 'email', 'minutes' => 24 * 60), array('method' => 'popup', 'minutes' => 10), ), ), )); $calendarId = 'primary'; $event = $service->events->insert($calendarId, $event); printf('Event created: %s\n', $event->htmlLink);
Ruby
event = Google::Apis::CalendarV3::Event.new( summary: 'Google I/O 2015', location: '800 Howard St., San Francisco, CA 94103', description: 'A chance to hear more about Google\'s developer products.', start: Google::Apis::CalendarV3::EventDateTime.new( date_time: '2015-05-28T09:00:00-07:00', time_zone: 'America/Los_Angeles' ), end: Google::Apis::CalendarV3::EventDateTime.new( date_time: '2015-05-28T17:00:00-07:00', time_zone: 'America/Los_Angeles' ), recurrence: [ 'RRULE:FREQ=DAILY;COUNT=2' ], attendees: [ Google::Apis::CalendarV3::EventAttendee.new( email: 'lpage@example.com' ), Google::Apis::CalendarV3::EventAttendee.new( email: 'sbrin@example.com' ) ], reminders: Google::Apis::CalendarV3::Event::Reminders.new( use_default: false, overrides: [ Google::Apis::CalendarV3::EventReminder.new( reminder_method: 'email', minutes: 24 * 60 ), Google::Apis::CalendarV3::EventReminder.new( reminder_method: 'popup', minutes: 10 ) ] ) ) result = client.insert_event('primary', event) puts "Event created: #{result.html_link}"
.NET
// Refer to the .NET quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/dotnet // Change the scope to CalendarService.Scope.Calendar and delete any stored // credentials. Event newEvent = new Event() { Summary = "Google I/O 2015", Location = "800 Howard St., San Francisco, CA 94103", Description = "A chance to hear more about Google's developer products.", Start = new EventDateTime() { DateTime = DateTime.Parse("2015-05-28T09:00:00-07:00"), TimeZone = "America/Los_Angeles", }, End = new EventDateTime() { DateTime = DateTime.Parse("2015-05-28T17:00:00-07:00"), TimeZone = "America/Los_Angeles", }, Recurrence = new String[] { "RRULE:FREQ=DAILY;COUNT=2" }, Attendees = new EventAttendee[] { new EventAttendee() { Email = "lpage@example.com" }, new EventAttendee() { Email = "sbrin@example.com" }, }, Reminders = new Event.RemindersData() { UseDefault = false, Overrides = new EventReminder[] { new EventReminder() { Method = "email", Minutes = 24 * 60 }, new EventReminder() { Method = "sms", Minutes = 10 }, } } }; String calendarId = "primary"; EventsResource.InsertRequest request = service.Events.Insert(newEvent, calendarId); Event createdEvent = request.Execute(); Console.WriteLine("Event created: {0}", createdEvent.HtmlLink);
Go
// Refer to the Go quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/go // Change the scope to calendar.CalendarScope and delete any stored credentials. event := &calendar.Event{ Summary: "Google I/O 2015", Location: "800 Howard St., San Francisco, CA 94103", Description: "A chance to hear more about Google's developer products.", Start: &calendar.EventDateTime{ DateTime: "2015-05-28T09:00:00-07:00", TimeZone: "America/Los_Angeles", }, End: &calendar.EventDateTime{ DateTime: "2015-05-28T17:00:00-07:00", TimeZone: "America/Los_Angeles", }, Recurrence: []string{"RRULE:FREQ=DAILY;COUNT=2"}, Attendees: []*calendar.EventAttendee{ &calendar.EventAttendee{Email:"lpage@example.com"}, &calendar.EventAttendee{Email:"sbrin@example.com"}, }, } calendarId := "primary" event, err = srv.Events.Insert(calendarId, event).Do() if err != nil { log.Fatalf("Unable to create event. %v\n", err) } fmt.Printf("Event created: %s\n", event.HtmlLink)
JavaScript
ใช้ไลบรารีของไคลเอ็นต์ JavaScript
// Refer to the JavaScript quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/js // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any // stored credentials. var event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles' }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': 'lpage@example.com'}, {'email': 'sbrin@example.com'} ], 'reminders': { 'useDefault': false, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10} ] } }; var request = gapi.client.calendar.events.insert({ 'calendarId': 'primary', 'resource': event }); request.execute(function(event) { appendPre('Event created: ' + event.htmlLink); });
Node.js
ใช้ไลบรารีของไคลเอ็นต์ Node.js
// Refer to the Node.js quickstart on how to setup the environment: // https://developers.google.com/calendar/quickstart/node // Change the scope to 'https://www.googleapis.com/auth/calendar' and delete any // stored credentials. var event = { 'summary': 'Google I/O 2015', 'location': '800 Howard St., San Francisco, CA 94103', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2015-05-28T09:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'end': { 'dateTime': '2015-05-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'recurrence': [ 'RRULE:FREQ=DAILY;COUNT=2' ], 'attendees': [ {'email': 'lpage@example.com'}, {'email': 'sbrin@example.com'}, ], 'reminders': { 'useDefault': false, 'overrides': [ {'method': 'email', 'minutes': 24 * 60}, {'method': 'popup', 'minutes': 10}, ], }, }; calendar.events.insert({ auth: auth, calendarId: 'primary', resource: event, }, function(err, event) { if (err) { console.log('There was an error contacting the Calendar service: ' + err); return; } console.log('Event created: %s', event.htmlLink); });
ลองใช้เลย
ใช้ API Explorer ด้านล่างเพื่อเรียกใช้เมธอดนี้ในข้อมูลสดและดูการตอบสนอง