简体   繁体   English

如何在 javascript 中通过谷歌日历 api 获得谷歌见面链接?

[英]How to get Google meet link thru google calendar api in javascript?

I want to create a line notify which can send the event detail from my google calendar everyday.我想创建一个线路通知,它可以每天从我的谷歌日历发送事件详细信息。
I can get the title, description, location...etc, but I don't see the conference data in calendar API.我可以获取标题、描述、位置...等,但在日历 API 中看不到会议数据。
I use Google Apps Script to run the code.我使用 Google Apps 脚本来运行代码。
Here is my code.这是我的代码。

const Now = new Date();
const Start = new Date(new Date().setHours(0, 0, 0, 0));
const End =  new Date(new Date().setHours(23, 59, 59, 999));
const calendarData = calendar.getEvents(Start, End);

function Notify() {
  var NotifyContents = '';
  var i = 1;
  calendarData.forEach(item =>{
      if (Now <= item.getStartTime()) {
        NotifyContents += (item.getTitle() != "") ? ("\n" + i+". "+ item.getTitle() + "\n") : ("\n\nNo Title\n");
        NotifyContents += (item.getDescription() != "") ? item.getDescription() + "\n" : "";
        NotifyContents += (item.getStartTime() != "" && item.getEndTime() != "") ? "Time:" + item.getStartTime().toLocaleTimeString() + "-" + item.getEndTime().toLocaleTimeString() + "\n": "";
        NotifyContents += (item.getconferencedata() != "") ? ("\n" + i+". "+ item.getconferencedata()) : ("No Conference\n");
        i++;
      }
    }
  )
  if (typeof NotifyContents === 'string' && NotifyContents.length === 0) {
    return;
  }
  NotifyTokens.forEach(function(value){
    UrlFetchApp.fetch("https://notify-api.line.me/api/notify", {
      "method"  : "post",
      "payload" : {"message" : NotifyContents},
      "headers" : {"Authorization" : "Bearer " + value}
    });
  });
}

Reference - Calendar API Link参考 - 日历 API 链接

In order to retrieve the meet link from the event, it seems that in the current stage, Calendar API is required to be used.为了从事件中检索见面链接,似乎在当前阶段需要使用日历 API。 When this is reflected in your script, how about the following modification?当这反映在您的脚本中时,如何进行以下修改?

Modified script:修改后的脚本:

Before you use this script, please enable Calendar API at Advanced Google services .在使用此脚本之前, 请在高级 Google 服务中启用日历 API

From:从:

var NotifyContents = '';
var i = 1;
calendarData.forEach(item => {
  if (Now <= item.getStartTime()) {
    NotifyContents += (item.getTitle() != "") ? ("\n" + i + ". " + item.getTitle() + "\n") : ("\n\nNo Title\n");
    NotifyContents += (item.getDescription() != "") ? item.getDescription() + "\n" : "";
    NotifyContents += (item.getStartTime() != "" && item.getEndTime() != "") ? "Time:" + item.getStartTime().toLocaleTimeString() + "-" + item.getEndTime().toLocaleTimeString() + "\n" : "";
    NotifyContents += (item.getconferencedata() != "") ? ("\n" + i + ". " + item.getconferencedata()) : ("No Conference\n");
    i++;
  }
}
)

To:至:

const eventList = Calendar.Events.list(calendar.getId(), { timeMin: Start.toISOString(), timeMax: End.toISOString(), maxResults: 2500 }).items.reduce((o, e) => (o[e.id] = e.conferenceData.entryPoints.map(({ uri }) => uri).join(","), o), {});
var NotifyContents = '';
var i = 1;
calendarData.forEach(item => {
  if (Now <= item.getStartTime()) {
    NotifyContents += (item.getTitle() != "") ? ("\n" + i + ". " + item.getTitle() + "\n") : ("\n\nNo Title\n");
    NotifyContents += (item.getDescription() != "") ? item.getDescription() + "\n" : "";
    NotifyContents += (item.getStartTime() != "" && item.getEndTime() != "") ? "Time:" + item.getStartTime().toLocaleTimeString() + "-" + item.getEndTime().toLocaleTimeString() + "\n" : "";
    var eventId = item.getId().split("@")[0];
    NotifyContents += eventList[eventId] != "" ? ("\n" + i + ". " + eventList[eventId]) : ("No Conference\n");
    i++;
  }
});
  • In this modification, it supposes that calendar has already been declaread.在这个修改中,它假设calendar已经被声明。 Please be careful about this.请注意这一点。

Reference:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何安排谷歌会议并在 NodeJs 中获取会议链接? - How to schedule a google meet and get the meet link in NodeJs? 如何使用 Google Apps 脚本将 Google Meet 链接添加到新的 Google 日历活动? - How to add a Google Meet link to a new Google Calendar Event using a Google Apps Script? 如何通过 Javascript 中的 Google 日历 API 获取 Google 日历中事件的位置? - How to get the location of an event in Google Calendar through the Google Calendar API in Javascript? 如何在JavaScript中获取Google日历事件的ColorID - how to get the ColorID of a Google Calendar Event in JavaScript Google 日历 API Javascript 问题 - Google Calendar API Issue with Javascript Google Calendar API Javascript快速添加 - Google Calendar API Javascript Quickadd 如何从Google的Calendar API获得指向附件的直接链接? - How do I get the direct link to an attached file from Google's Calendar API? Javascript Google Calendar API将日历设置为公开 - Javascript Google Calendar API Set Calendar to Public javascript中如何获取谷歌日历中单个日历的事件文本 - How to get the event text of a single calendar in Google calendar in javascript 如何在 Javascript 2022 中创建 Google 日历链接日期? - How to create Google calendar link date in Javascript 2022?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM