首页 > 解决方案 > Google Calendar API v3 未保存活动地点和与会者

问题描述

我正在测试Google Calendar API v3,唯一缺少的字段是location获取attendees日历事件。我正在使用 REST 接口(google oauth2 和我登录的用户是日历所有者),我可以进行所有所需的 CRUD 操作,但由于某种原因,locationattendees忽略了。如果我在Google API Explorer或 Postman中使用相同的有效负载(从控制台输出复制),它可以工作......我错过了什么?

示例播放负载:

POST https://www.googleapis.com/calendar/v3/calendars/[YOUR_CALENDAR_ID]/events?key=[YOUR_API_KEY] HTTP/1.1

Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Content-Type: application/json

{
  "end": {
    "timeZone": "Europe/Lisbon",
    "dateTime": "2021-05-13T10:00:00+01:00"
  },
  "start": {
    "timeZone": "Europe/Lisbon",
    "dateTime": "2021-05-13T08:00:00+01:00"
  },
  "attendees": [
    {
      "email": "batman@mail.com"
    }
  ],
  "location": "Batcave"
}

我正在使用 Ktor,这是代码:

client.post<Event>("https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events") {
    body = event
    parameter(API_KEY_PARAMETER, apiKey)
    contentType(ContentType.Application.Json)
    header(HttpHeaders.Authorization, token)
}

其中事件:

@Serializable
data class Event(
    val id: String = "",
    val status: String = "",
    val created: String = "",
    val updated: String = "",
    val creator: Attendee,
    val start: DateLabel,
    val end: DateLabel,
    val summary: String = "",
    val description: String = "",
    val location: String = "",
    val attendees: List<Attendee> = emptyList(),
    val maxAttendees: Int = 5
)

@Serializable
data class DateLabel(
    val date: String = "",
    val dateTime: String = "",
    val timeZone: String = ""
)

@Serializable
data class Attendee(val email: String)

标签: kotlingoogle-cloud-platformgoogle-apigoogle-calendar-apiktor

解决方案


推荐阅读