繁体   English   中英

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

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

我想创建一个线路通知,它可以每天从我的谷歌日历发送事件详细信息。
我可以获取标题、描述、位置...等,但在日历 API 中看不到会议数据。
我使用 Google Apps 脚本来运行代码。
这是我的代码。

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

参考 - 日历 API 链接

为了从事件中检索见面链接,似乎在当前阶段需要使用日历 API。 当这反映在您的脚本中时,如何进行以下修改?

修改后的脚本:

在使用此脚本之前, 请在高级 Google 服务中启用日历 API

从:

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

至:

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++;
  }
});
  • 在这个修改中,它假设calendar已经被声明。 请注意这一点。

参考:

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM