如何在GS中使用扩展属性插入Google事件?

发布于 2025-01-24 04:00:24 字数 2946 浏览 2 评论 0 原文

我想在Google script = .gs文件中添加 /插入具有扩展属性的新事件。

我找到了日历api的代码示例 - evestion 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': '[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"];


}

I want to add / insert new event with extened properties in Google Script = .gs file.

I found code example for Calendar API - Events insert - see below. But the code uses the JavaScript client library. I want the code to run from GS file. I tried to modify but it did not work.

When using the code I want to be able to specify any calendar. Not only "primary".

// 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);
});

Could someone please explain the difference between private and shared extended properties?

I am able to create new event using below code but looks like it will not store extended properties.

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"];


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿港巷口少年归 2025-01-31 04:00:24

问题1:

有人可以解释私人和共享扩展属性之间的区别吗?

官方文件显示如下。

  • ExtendedProperties.private :属于此日历上事件副本的属性。
  • ExtendedProperties.shared :事件副本之间在其他与会者日历上共享的属性。

例如,当创建一个新事件,并使用 extendedProperties.private and extendedProperties.shared 通过包括与会者,您可以看到两个值。但是,与会者只能看到 ExtendedProperties.shared 的值。

这种解释有用吗?

问题2的答案:

我想在Google脚本= .gs文件中添加 /插入带有扩展属性的新事件。< / p>

当我看到 createEvent方法的正式文档(标题,开始时间,末日,选项)时,似乎 options 没有 ExtendedProperties 。 ref 我认为这是您问题的原因。如果要创建一个新事件,包括 extendedProperties.private ExtendedProperties.shared 的值,如何使用高级Google Services的日历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 的值。

参考:

Answer for question 1:

Could someone please explain the difference between private and shared extended properties?

The official document says as follows.

  • 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.

For example, when a new event is created with the values of extendedProperties.private and extendedProperties.shared by including the attendees, you can see both values. But, the attendees can see only the value of extendedProperties.shared.

Is this explanation useful?

Answer for question 2:

I want to add / insert new event with extened properties in Google Script = .gs file.

When I saw the official document of the method of createEvent(title, startTime, endTime, options), it seems that options has no property of extendedProperties. Ref I thought that this is the reason for your issue. If you want to create a new event including the values of extendedProperties.private and extendedProperties.shared, how about using Calendar API of Advanced Google services?

The sample script is as follows.

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)
  • When this script is run by the owner of the calendar, you can see both values of extendedProperties.private and extendedProperties.shared.
  • When you get this event by the attendee, you can see only the value of extendedProperties.shared.

References:

怕倦 2025-01-31 04:00:24

有人可以解释私人和共享扩展属性之间的区别吗?
基于文档> documentation ,共享的扩展属性是可见的,而与会者可见且可在私人设置一位与会者的当地“副本”。

要使用应用程序脚本添加扩展属性,您可以使用高级日历服务< /a>。为此,您需要在应用程序脚本项目中添加“ Google Calendar API”服务,在屏幕的左侧,单击“服务”旁边的“+”,搜索“ 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);
}

Could someone please explain the difference between private and shared extended properties?
Based on documentation, shared extended properties are visible and editable by attendees while private set on one attendee's local "copy" of the event.

To add extended properties to events with Apps Script, you can do it with the advanced Calendar service. For this, you need to add the “Google Calendar API” service in your Apps Script project, on the left side of the screen, click on the “+” next to “Services”, search for “Google Calendar API”, click on it and click “Add”.

After completing the steps mentioned above, you can test this script I created as an example.

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文