我正在编写一个可以与 Google 日历同步的离线日历。它可以从谷歌日历获取数据,但不能向谷歌插入事件。这是我的插入代码:
var url = 'https://www.googleapis.com/calendar/v3/calendars/' + calendar_id + '/events';
var request = {
'method': 'POST',
'headers': {
'GData-Version': '3.0',
'Content-Type': 'application/atom+xml'
},
'body': {
'start': { 'dateTime': '2012-07-24T07:30:00+08:00'},
'end': { 'dateTime': '2012-07-24T08:30:00+08:00'},
'summary': calEvent.title,
'description': calEvent.body,
'attendees': [ { 'email': calendar_id}],
'reminders': {
'overrides': [ {'method': 'email', 'minutes': 15}]
}
}
};
oauth.sendSignedRequest(url, function(resp) { console.log(resp) }, request);
查了好几遍,也查了一些相关的问题,还是没搞清楚哪里错了。这是返回错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
最佳答案
我找出错误的地方。请求的主体必须是字符串。
var body = {
'start': { 'dateTime': '2012-07-24T07:30:00+08:00'},
'end': { 'dateTime': '2012-07-24T08:30:00+08:00'},
'summary': calEvent.title,
'description': calEvent.body,
'attendees': [ { 'email': calendar_id}],
'reminders': {
'overrides': [ {'method': 'email', 'minutes': 15}]
}
}
然后将正文变成字符串:
body = JSON.stringify(body)
设置请求变量:
request = {
.....
'body': body
.....
}
关于javascript - Chrome 扩展将事件添加到 Google 日历发生 'Parse Error',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11648090/