Google Calendar.Insert API返回400'必填'

Ben*_*hes 8 javascript google-calendar-api

我正在尝试通过Google JavaScript API创建日历.OAuth身份验证工作正常:我可以使用以下命令获取日历列表:

gapi.client.calendar.calendarList.list();
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用以下命令创建日历时:

gapi.client.calendar.calendars.insert(
{
    "summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"
});
Run Code Online (Sandbox Code Playgroud)

我明白了:

{
  "error": {
  "code": 400,
  "message": "Required",
  "data": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required"
   }
  ]
 },
 "id": "gapiRpc"
}
Run Code Online (Sandbox Code Playgroud)

doco中,对于其他API,它会显示此响应,但会显示缺少所需参数的列表.

有没有办法确定我缺少的"必需"参数?我已经使用API Explorer测试了它,我的参数似乎工作正常.

Ben*_*hes 22

终于搞清楚了.属性需要位于"资源"对象中:

gapi.client.calendar.calendars.insert(
{
    "resource" :
    {"summary": "A New Calendar",
    "description": "Generated by Ben",
    "timezone" : "Australia/Sydney"}
});
Run Code Online (Sandbox Code Playgroud)

doco没有提到这一点,但如果你查看对初始调用的响应,gapi.auth.authorize你会发现JSON描述了你指定范围的整个API.