Google Calendar API 显示错误且响应不佳

问题描述 投票:0回答:0

我正在尝试创建一个向用户发送日历邀请的功能,但它无法正常工作? Google Calendar API 显示错误且响应不佳 代码

const {google} = require('googleapis');
const { GoogleAuth } = require('google-auth-library');


function sendCalendarInvite(email, users, time, subject, description) {
  // Authenticate with the Google Calendar API
  // const auth = new google.auth.GoogleAuth({
    const auth = new google.auth.JWT({
      keyFilename: "new.json",
      scopes: ["https://www.googleapis.com/auth/calendar"],
    });
  const calendar = google.calendar({ version: 'v3', auth });

  // Build the calendar invite event
  const event = {
    summary: subject,
    description: description,
    start: { dateTime: time.start },
    end: { dateTime: time.end },
    attendees: users.map((user) => ({ email: user })),
    reminders: { useDefault: true },
    conferenceDataVersion: 1,
  };`

  console.log(event);
  // Send the calendar invite to the specified email
  const res = calendar.events.insert({
    auth: auth,
    calendarId: 'primary',
    sendUpdates: 'all',
    resource: event,
  }, function(err, event){
    // console.log("Event Created %s", event.data);
    if(err){
      console.log("There was a error in contacting the calender service", + err);
      return;
    }
    console.log("Event Created %s", event.data.htmlLink);
  });

  console.log(`Calendar invite sent to ${email}`);
  console.log(res);
}

日历邀请已发送至####### 不明确的 联系日历服务 NaN

时出错

我很困惑,是代码问题还是API错误。我知道这个问题已经有了答案,但我无法解决我的问题,所以我希望你能帮助我,或者至少建议我尝试什么,因为我不确定该做什么或怎么做调试以解决我的问题。

javascript node.js typescript google-api google-calendar-api
© www.soinside.com 2019 - 2024. All rights reserved.