I am writing an offline calendar which can sync with Google Calendar. It can get data from Google Calendar, but can't insert events to Google. Here is my inserting code:
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);
I have checked several times and searched some related problems, still can't figure out where is wrong. Here is the return errors:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
I figure out where is wrong. The body of the request must be strings.
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}]
}
}
Then turn the body into strings:
body = JSON.stringify(body)
Set the request variable:
request = {
.....
'body': body
.....
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.