我想在 Google Script = .gs 檔案中添加/插入具有擴展屬性的新事件。
我找到了日歷 API 的代碼示例 -事件插入- 見下文。但是代碼使用了 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': '[email protected]'},
{'email': '[email protected]'}
],
'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 = '[email protected]'
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"];
}
uj5u.com熱心網友回復:
問題 1 的答案:
有人可以解釋私有和共享擴展屬性之間的區別嗎?
官方檔案是這樣說的。
extendedProperties.private:此日歷上顯示的事件副本的私有屬性。extendedProperties.shared:在其他與會者日歷上的活動副本之間共享的屬性。
例如,當使用參與者的值創建新事件extendedProperties.private并extendedProperties.shared包含參與者時,您可以看到這兩個值。但是,與會者只能看到 的值extendedProperties.shared。
這個解釋有用嗎?
問題 2 的答案:
我想在 Google Script = .gs 檔案中添加/插入具有擴展屬性的新事件。
當我看到方法的官方檔案時createEvent(title, startTime, endTime, options),似乎options沒有 的屬性extendedProperties。參考我認為這是您的問題的原因。如果您想創建一個包含 和 值的新事件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。
參考:
- createEvent(標題,開始時間,結束時間,選項)
- 事件:插入
uj5u.com熱心網友回復:
有人可以解釋私有和共享擴展屬性之間的區別嗎? 根據檔案,與會者可以看到和編輯共享的擴展屬性,而在一位與會者的本地活動“副本”上設定私有屬性。
要使用 Apps 腳本為事件添加擴展屬性,您可以使用高級日歷服務來完成。為此,您需要在您的 Apps Script 專案中添加“Google Calendar API”服務,在螢屏左側,點擊“Services”旁邊的“ ”,搜索“Google Calendar API”,點擊它并單擊“添加”。
完成上述步驟后,您可以測驗我創建的這個腳本作為示例。
function createEvent() {
var calendarId = '[email protected]' //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);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/468296.html
