My code (pretty straight forward):
var google = require('googleapis');
var key = require('../../ssl/GoogleAPI/calendar-secret.json');
var auth = new google.auth.JWT(key.client_email, null, key.private_key, ['https://www.googleapis.com/auth/calendar'], null);
var api = google.calendar("v3");
auth.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
}
api.calendars.insert({
auth: auth,
summary: "test calendar"
}, function (err, resp) {
if (err) {
console.log(err);
}
else {
console.log(resp);
}
})
});
I get a response saying:
{ [Error: Missing title.]
code: 400,
errors:
[ { domain: 'global',
reason: 'required',
message: 'Missing title.' } ] }
I tried tracing the code and it seems like there is nothing in the body of the POST.
Not sure if the syntax is correct for the params
object but I followed the examples as much as I could.
The API doc specify the title is 'summary' as in
POST https://www.googleapis.com/calendar/v3/calendars
{
"summary": "test-cal2"
}
So, what am I doing wrong here?
Digging through the code I finally got this working by using:
api.calendars.insert({
auth: auth,
resource: {summary: "test calendar 2"}
}
Where is the doc on this stuff?
This was not clear at all...
It's documented in the README https://github.com/google/google-api-nodejs-client#specifying-request-body How can I make it more clear?
I know I'm replying to a 2-year-old post but it's a problem that persists.
There is no example showing explicitly how to insert something, to any of your APIs, or at least it's not very visible. That's the biggest thing you could add to make this better.
There's a LOT more... but I won't go into it.
this function should do the job. https://github.com/google/google-api-nodejs-client/blob/master/src/apis/calendar/v3.ts#L662
trying the official API test
https://developers.google.com/google-apps/calendar/v3/reference/calendars/insert#try-it
is working
I can't get it to work too.
This is my code:
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
oauth2Client.credentials = JSON.parse(user.calendarToken)
var calendar = google.calendar('v3');
calendar.calendars.insert({
resource : {
summary : req.body.newName
},
auth: auth
},function(err,newCal){
console.log(err) /* => output this { domain: 'global',
reason: 'required',
message: 'Missing title.' }*/
})
Most helpful comment
Digging through the code I finally got this working by using:
Where is the doc on this stuff?
This was not clear at all...