如何在 GS 中插入具有扩展属性的 Google 事件?
How to insert Google Event with Extended Properties in GS?
我想在 Google Script = .gs 文件中添加/插入具有扩展属性的新事件。
我找到了日历的代码示例 API - Events insert - 见下文。但是代码使用 JavaScript 客户端库。我希望 GS 文件中的代码为 运行。我尝试修改,但没有成功。
使用代码时,我希望能够指定任何日历。不仅是“初级”。
// 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);
});
有人可以解释一下私有和共享扩展属性之间的区别吗?
我可以使用以下代码创建新事件,但看起来它不会存储扩展属性。
function getCalendar() {
var calendarId = 'processor@mydomain.com'
var calendar = CalendarApp.getCalendarById(calendarId)
Logger.log('The calendar is named "%s".', calendar.getName());
var eventOption = {
location: 'The Moon',
description: 'link na akci je https://us02web.zoom.us/j/83314336043',
extendedProperties: { // Extended properties of the event.
private: { // Properties that are private to the copy of the event that appears on this calendar.
creator: "Radek", // The name of the private property and the corresponding value.
},
}
}
var event = calendar.createEvent('test event from the script',
new Date(),
new Date(),
eventOption
);
var eventId = event.getId().replace(/@.*/,'') // // Remove @google.com from eventId
Logger.log('Event ID: ' + eventId)
calendarId = 'primary'
var eventSaved = Calendar.Events.get(encodeURIComponent(calendarId), eventId)
var testEx = event.extendedProperties
var test = event.extendedProperties.private["creator"];
}
问题 1 的答案:
Could someone please explain the difference between private and shared extended properties?
官方文档是这样说的
extendedProperties.private
: Properties that are private to the copy of the event that appears on this calendar.
extendedProperties.shared
: Properties that are shared between copies of the event on other attendees' calendars.
例如,当通过包括与会者使用值 extendedProperties.private
和 extendedProperties.shared
创建新事件时,您可以看到这两个值。但是,与会者只能看到 extendedProperties.shared
.
的值
这个解释有用吗?
问题 2 的答案:
I want to add / insert new event with extened properties in Google Script = .gs file.
我看createEvent(title, startTime, endTime, options)
方法的官方文档时,好像options
没有extendedProperties
的属性。 Ref 我认为这就是您遇到问题的原因。如果您想创建一个包含 extendedProperties.private
和 extendedProperties.shared
值的新事件,使用高级 Google 服务的日历 API 怎么样?
示例脚本如下
const calendarId = "###"; // Please set your calendar ID.
// Create a new event including extendedProperties.
const params = {
start: { dateTime: "2022-04-27T00:00:00Z" },
end: { dateTime: "2022-04-27T01:00:00Z" },
extendedProperties: {
private: { key1: "value1" },
shared: { key2: "value2" }
},
summary: "sample",
attendees: [{ email: "###" }] // Please set the email of attendee, if you want to include.
};
const res1 = Calendar.Events.insert(params, calendarId);
// Check the value of extendedProperties
const res2 = Calendar.Events.get(calendarId, res1.id);
console.log(res2.extendedProperties)
- 当此脚本由日历所有者 运行 时,您可以看到
extendedProperties.private
和 extendedProperties.shared
的值。
- 当您通过与会者获取此事件时,您只能看到
extendedProperties.shared
的值。
参考文献:
有人可以解释一下私有和共享扩展属性之间的区别吗?
基于 documentation,与会者可以看到和编辑共享扩展属性,而在一位与会者的活动本地“副本”上设置为私有。
要使用 Apps 脚本向事件添加扩展属性,您可以使用 advanced Calendar service。为此,您需要在 Apps Script 项目中添加“Google Calendar API”服务,在屏幕左侧,点击“Services”旁边的“+”,搜索“Google日历API”,点击它,然后点击“添加”。
完成上述步骤后,您可以测试我创建的这个脚本作为示例。
function createEvent() {
var calendarId = 'processor@mydomain.com' //you can specify the calendar with the calendar id
var start = new Date();
var end = new Date();
var event = {
"location": "The Moon",
"description": "link na akci je https://us02web.zoom.us/j/83314336043",
"start": {
"dateTime": start.toISOString(),
},
"end": {
"dateTime": end.toISOString()
},
"extendedProperties": {
"private": {
"creator": "Radek"
}
}
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.id);
}
我想在 Google Script = .gs 文件中添加/插入具有扩展属性的新事件。
我找到了日历的代码示例 API - Events insert - 见下文。但是代码使用 JavaScript 客户端库。我希望 GS 文件中的代码为 运行。我尝试修改,但没有成功。
使用代码时,我希望能够指定任何日历。不仅是“初级”。
// 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);
});
有人可以解释一下私有和共享扩展属性之间的区别吗?
我可以使用以下代码创建新事件,但看起来它不会存储扩展属性。
function getCalendar() {
var calendarId = 'processor@mydomain.com'
var calendar = CalendarApp.getCalendarById(calendarId)
Logger.log('The calendar is named "%s".', calendar.getName());
var eventOption = {
location: 'The Moon',
description: 'link na akci je https://us02web.zoom.us/j/83314336043',
extendedProperties: { // Extended properties of the event.
private: { // Properties that are private to the copy of the event that appears on this calendar.
creator: "Radek", // The name of the private property and the corresponding value.
},
}
}
var event = calendar.createEvent('test event from the script',
new Date(),
new Date(),
eventOption
);
var eventId = event.getId().replace(/@.*/,'') // // Remove @google.com from eventId
Logger.log('Event ID: ' + eventId)
calendarId = 'primary'
var eventSaved = Calendar.Events.get(encodeURIComponent(calendarId), eventId)
var testEx = event.extendedProperties
var test = event.extendedProperties.private["creator"];
}
问题 1 的答案:
Could someone please explain the difference between private and shared extended properties?
官方文档是这样说的
extendedProperties.private
: Properties that are private to the copy of the event that appears on this calendar.extendedProperties.shared
: Properties that are shared between copies of the event on other attendees' calendars.
例如,当通过包括与会者使用值 extendedProperties.private
和 extendedProperties.shared
创建新事件时,您可以看到这两个值。但是,与会者只能看到 extendedProperties.shared
.
这个解释有用吗?
问题 2 的答案:
I want to add / insert new event with extened properties in Google Script = .gs file.
我看createEvent(title, startTime, endTime, options)
方法的官方文档时,好像options
没有extendedProperties
的属性。 Ref 我认为这就是您遇到问题的原因。如果您想创建一个包含 extendedProperties.private
和 extendedProperties.shared
值的新事件,使用高级 Google 服务的日历 API 怎么样?
示例脚本如下
const calendarId = "###"; // Please set your calendar ID.
// Create a new event including extendedProperties.
const params = {
start: { dateTime: "2022-04-27T00:00:00Z" },
end: { dateTime: "2022-04-27T01:00:00Z" },
extendedProperties: {
private: { key1: "value1" },
shared: { key2: "value2" }
},
summary: "sample",
attendees: [{ email: "###" }] // Please set the email of attendee, if you want to include.
};
const res1 = Calendar.Events.insert(params, calendarId);
// Check the value of extendedProperties
const res2 = Calendar.Events.get(calendarId, res1.id);
console.log(res2.extendedProperties)
- 当此脚本由日历所有者 运行 时,您可以看到
extendedProperties.private
和extendedProperties.shared
的值。 - 当您通过与会者获取此事件时,您只能看到
extendedProperties.shared
的值。
参考文献:
有人可以解释一下私有和共享扩展属性之间的区别吗? 基于 documentation,与会者可以看到和编辑共享扩展属性,而在一位与会者的活动本地“副本”上设置为私有。
要使用 Apps 脚本向事件添加扩展属性,您可以使用 advanced Calendar service。为此,您需要在 Apps Script 项目中添加“Google Calendar API”服务,在屏幕左侧,点击“Services”旁边的“+”,搜索“Google日历API”,点击它,然后点击“添加”。
完成上述步骤后,您可以测试我创建的这个脚本作为示例。
function createEvent() {
var calendarId = 'processor@mydomain.com' //you can specify the calendar with the calendar id
var start = new Date();
var end = new Date();
var event = {
"location": "The Moon",
"description": "link na akci je https://us02web.zoom.us/j/83314336043",
"start": {
"dateTime": start.toISOString(),
},
"end": {
"dateTime": end.toISOString()
},
"extendedProperties": {
"private": {
"creator": "Radek"
}
}
};
event = Calendar.Events.insert(event, calendarId);
Logger.log('Event ID: ' + event.id);
}