我正在尝试通过Google JavaScript API创建日历。 OAuth身份验证工作正常:我可以使用以下命令获取日历列表:
gapi.client.calendar.calendarList.list();
但是,当我尝试使用以下内容创建日历时
gapi.client.calendar.calendars.insert(
{
"summary": "A New Calendar",
"description": "Generated by Ben",
"timezone" : "Australia/Sydney"
});
我明白了:
{
"error": {
"code": 400,
"message": "Required",
"data": [
{
"domain": "global",
"reason": "required",
"message": "Required"
}
]
},
"id": "gapiRpc"
}
在doco for other APIs中,它会显示此响应,但会显示缺少所需参数的列表。
有没有办法确定我缺少什么'必需'参数?我已经使用API Explorer对其进行了测试,我的参数似乎工作正常。
答案 0 :(得分:22)
终于弄明白了。属性需要位于“资源”对象中:
gapi.client.calendar.calendars.insert(
{
"resource" :
{"summary": "A New Calendar",
"description": "Generated by Ben",
"timezone" : "Australia/Sydney"}
});
doco没有提到这一点,但是如果你看一下对gapi.auth.authorize
的初始调用的响应,你会发现JSON描述了你指定范围的整个API。