0

我有一个节点应用程序,我使用 netlify dev 在 lamda 函数中本地运行。我收到 500 响应错误,不知道为什么我很确定我拥有所有正确的凭据。我不知道如何调试这个。希望有人可以帮助我阅读有关尝试发送响应 3s 然后 6s 等的内容,但仍然返回完全相同的问题。这是我第一次使用 api,所以不确定该怎么做。

请记住,我使用开发者游乐场作为我的 oauth 重定向,并在那里生成了一个刷新令牌

const { google } = require("googleapis")
const { oAuth2 } = google.auth


    const oAuth2Client = new oAuth2(
      "fdsfs.apps.googleusercontent.com",
      "fdsaf"
    )

    oAuth2Client.setCredentials({
      refresh_token:
        "1//0fdsfas",
    })

    // Create a new calender instance.
    const calendar = google.calendar({ version: "v3", auth: oAuth2Client })

    // Create a new event start date instance for temp uses in our calendar.
    const eventStartTime = new Date()
    eventStartTime.setDate(eventStartTime.getDay() + 2)

    // Create a new event end date instance for temp uses in our calendar.
    const eventEndTime = new Date()
    eventEndTime.setDate(eventEndTime.getDay() + 4)
    eventEndTime.setMinutes(eventEndTime.getMinutes() + 45)

    // Create a dummy event for temp uses in our calendar
    const event = {
      summary: `Meeting with David`,
      location: `3595 California St, San Francisco, CA 94118`,
      description: `Meet with David to talk about the new client project and how to integrate the calendar for booking.`,
      colorId: 1,
      start: {
        dateTime: eventStartTime,
        timeZone: "America/Denver",
      },
      end: {
        dateTime: eventEndTime,
        timeZone: "America/Denver",
      },
    }

    // Check if we a busy and have an event on our calendar for the same time.
    calendar.freebusy.query(
      {
        resource: {
          timeMin: eventStartTime,
          timeMax: eventEndTime,
          timeZone: "America/Denver",
          items: [{ id: "primary" }],
        },
      },
      (err, res) => {
        // Check for errors in our query and log them if they exist.
        if (err) return console.error("Free Busy Query Error: ", err)

        // Create an array of all events on our calendar during that time.
        const eventArr = res.data.calendars.primary.busy

        // Check if event array is empty which means we are not busy
        if (eventArr.length === 0)
          // If we are not busy create a new calendar event.
          return calendar.events.insert(
            { calendarId: "primary", resource: event },
            err => {
              // Check for errors and log them if they exist.
              if (err)
                return console.error("Error Creating Calender Event:", err)
              // Else log that the event was created.
              return console.log("Calendar event successfully created.")
            }
          )

        // If event array is not empty log that we are busy.
        return console.log(`Sorry I'm busy...`)
      }
    )
4

1 回答 1

1

这是一个简单的错误

const { OAuth2 } = google.auth with capital O !not oAuth2

于 2020-05-16T19:14:29.627 回答