【问题标题】:Getting a 500 error for google calendar request谷歌日历请求出现 500 错误
【发布时间】:2020-05-14 20:51:58
【问题描述】:

我有一个节点应用程序,我使用 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...`)
      }
    )

【问题讨论】:

  • 请编辑您的问题并包含完整的错误消息。另请记住,操场令牌不会持续很长时间,它们仅用于测试。
  • 您好@AndersKitson,您为此使用了什么范围?您还可以使用日历 API reference 复制请求吗?
  • 我将测试您发送的参考。并且没有完整的错误消息,它只是 500 没有消息正文。我创建了新的游乐场令牌进行测试,所以不确定。
  • 您收到的是哪个代码?你能创建一个新的事件吗?另外,在这种情况下,您可能需要查看Calendar API Quickstart
  • 我无法创建新活动,我收到的唯一代码是 500。今晚我将尝试快速入门,谢谢

标签: google-calendar-api oauth2-playground


【解决方案1】:

这是一个简单的错误

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 2013-08-11
    • 1970-01-01
    • 2018-09-27
    相关资源
    最近更新 更多