【问题标题】:Google Calendar API - Clear all eventsGoogle Calendar API - 清除所有事件
【发布时间】:2021-11-15 11:13:47
【问题描述】:

我正在尝试使用日历 ID 清除 Google 日历的所有事件。

https://developers.google.com/resources/api-libraries/documentation/calendar/v3/python/latest/calendar_v3.calendars.html#clear

尝试它,从 Python 或使用 Google API Explorer 的简单 curl 调用给出“400 Bad Request”响应:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

从 API 资源管理器或 python API 中,我只提供我要删除的相应(非主要)日历的日历 ID。

在 Python 中:

service.calendars().clear(calendarId=<calid-found-in-calendarList().list()>).execute()

返回:

<HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/<calendar-id>4%40group.calendar.google.com/clear? returned "Invalid Value". Details: "[{'domain': 'global', 'reason': 'invalid', 'message': 'Invalid Value'}]">

知道我做错了什么吗?

【问题讨论】:

  • 您好,您能确认您传递的calendarId 是有效的吗?您是否能够从“试用此 API”工具here 执行相同的请求?
  • 嗨@ale13,我已经尝试过使用你提到的工具。我传递了一个有效的日历 ID,它由对 service.calendarList().list 的调用返回。如果我传递了一个无效的 ID(例如,通过更改有效 ID 的几个字母),我会收到“404 Not Found”
  • 这是您的个人日历吗?或者你想清除什么样的日历?
  • 这是个人日历,但我的主要日历。
  • 您最终是否在 Google 的问题跟踪器上报告了此行为?另外,你给这个日历做了哪些设置?

标签: google-calendar-api google-api-client


【解决方案1】:

之前我在 Calendar API v3 中测试过 Calendars 的 clear 方法时,我也遇到过和你一样的情况。当我使用primary 的值时,没有出现错误。主日历的所有事件都将被删除。但是,当我使用除主日历之外的日历 ID 时,发生了同样的问题。

当我看到the official document 时,它说的是Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account.。但是关于calendarId在这个方法中,也写了Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the "primary" keyword.

这些文件让我很困惑。所以,我在 Discovery API 上检查了这个“清除”方法。 Ref 如下。

"clear": {
  "parameters": {
    "calendarId": {
      "location": "path",
      "required": true,
      "type": "string",
      "description": "Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the \"primary\" keyword."
    }
  },
  "scopes": [
    "https://www.googleapis.com/auth/calendar"
  ],
  "httpMethod": "POST",
  "id": "calendar.calendars.clear",
  "description": "Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account.",
  "parameterOrder": [
    "calendarId"
  ],
  "path": "calendars/{calendarId}/clear"
},

从上面的文档中,我认为可以通过 calendarList.list 方法检索日历 ID。但是,这种“清除”方法可能无法用于除主日历之外的日历。

而且,当我看到错误信息时,当使用像###@group.calendar.google.com 这样的日历ID 时,会出现"message": "Invalid Value" 的错误。但是,当 sample 用作日历 ID 时,将返回 "message": "Not Found"。似乎 API 可能会搜索日历。在这种情况下,即使使用 URL 编码,也会出现同样的问题。从这种情况来看,我认为这可能是一个错误。

但是,我不确定这是当前规范还是错误。所以,我在问题跟踪器上搜索了这种情况。但是,不幸的是,我找不到同样的问题。那么在 Google 问题跟踪器上报告这个怎么样? Ref

参考:

【讨论】:

  • 谢谢@Tanaike,我不妨提出这个问题 :)
  • @bergercookie 感谢您的回复。另外,我想建议报告它。很抱歉,我无法直接解决您的问题。
  • 嗨@Tanaike,我仍然有同样的问题(现在是 2020 年 2 月)。你有没有找到解决方法或任何东西?也许我需要尝试获取辅助日历中的所有事件并批量删除它们,如果可能需要检查文档。
  • @Evgeny 在现阶段,这个问题似乎还没有解决。我对此深表歉意。作为当前的解决方法,如何检索所有事件 ID 并将其删除?
  • @Tanaike 我试过了,但是 API 有速率限制,我需要支持指数调用,删除所有事件需要很长时间。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-03
  • 2022-01-09
相关资源
最近更新 更多