gpt4 book ai didi

javascript - Chrome 扩展将事件添加到 Google 日历发生 'Parse Error'

转载 作者:行者123 更新时间:2023-11-30 13:17:06 24 4
gpt4 key购买 nike

我正在编写一个可以与 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com