尝试它时,从Python或使用Google API Explorer的简单curl调用给出"400 Bad Request“响应:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
],
"code": 400,
"message": "Invalid Value"
}
}
在API explorer或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'}]">
知道我做错了什么吗?
发布于 2021-11-16 02:07:10
当我之前测试过Calendar API v3中的日历的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中检查了这个"clear“方法。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编码,也会发生相同的问题。从这种情况来看,我认为这可能是一个bug。
但是,我不确定这是当前的规范还是bug。所以,我在问题跟踪器上搜索了这种情况。但是,不幸的是,我找不到同样的问题。那么,在谷歌问题跟踪器上报告这件事怎么样?Ref
参考资料:
https://stackoverflow.com/questions/69973489
复制相似问题