Closed atilling closed 3 years ago
in a chat with support it seems that the format for the CalendarId has changed https://gsuiteupdates.googleblog.com/2020/05/change-to-format-of-secondary-calendar.html the logic may need to be updated to accommodate that change.
Greetings! I just tried something similar with the latest version of the module, 52.1.0
, and everything appears to be working. I used this code:
const path = require('path');
const {google} = require('googleapis');
const {authenticate} = require('@google-cloud/local-auth');
async function main() {
const auth = await authenticate({
scopes: ['https://www.googleapis.com/auth/calendar'],
keyfilePath: path.resolve('../keys/oauth2.keys.json'),
});
google.options({auth});
const calendar = google.calendar('v3');
const res = await calendar.events.get({
calendarId: 'google.com_3gbcnczzzzzzzzzzzzz8abftc@group.calendar.google.com',
eventId: 'zzzzzzzzzzzzzzzz',
});
console.log(res.data);
}
main();
Could I trouble you to update to the latest version of the module and let us know if you run into the same problem?
Note: to run this code:
mkdir eventy
cd eventy
npm init -y
npm install googleapis @google-cloud/local-auth
touch server.js
# put the code above in server.js
node server.js
NPM is gave me version 47 and the error still happens. What is the correct way to grab version 52?
The best way is to update the version in your package.json, and run 'npm install'.
Updated to 52.1.0 still 404 Error:
{
"errorType": "Error",
"errorMessage": "Not Found",
"code": 404,
"response": {
"config": {
"url": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8",
"method": "GET",
"userAgentDirectives": [
{
"product": "google-api-nodejs-client",
"version": "4.3.0",
"comment": "gzip"
}
],
"headers": {
"x-goog-api-client": "gdcl/4.3.0 gl-node/12.16.3 auth/6.0.1",
"Accept-Encoding": "gzip",
"User-Agent": "google-api-nodejs-client/4.3.0 (gzip)",
"Authorization": "Bearer ya29.c.KpMBzgdYwb6AVurs1gP9fDRw4DMA1ys6ux77JueidiXXeloVDj0vw_hrAcu-souTl28QTrBIAYgz8OFqu7PUCwpy8NhUa2B5SyxYuoAJPAdtWm8dBYNw2xRLc6lK7F5t7cBye95H98B_lyZqeMQAj2p5w4xdxdps2HY7dpyEvNsiN2O_qugQSxzHHV-9NeBSZe0xHoD5",
"Accept": "application/json"
},
"params": {},
"retry": true,
"responseType": "json",
"retryConfig": {
"currentRetryAttempt": 0,
"retry": 3,
"httpMethodsToRetry": [
"GET",
"HEAD",
"PUT",
"OPTIONS",
"DELETE"
],
"noResponseRetries": 2,
"statusCodesToRetry": [
[
100,
199
],
[
429,
429
],
[
500,
599
]
]
}
},
"data": {
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
},
"headers": {
"alt-svc": "h3-27=\":443\"; ma=2592000,h3-25=\":443\"; ma=2592000,h3-T050=\":443\"; ma=2592000,h3-Q050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\"",
"cache-control": "private, max-age=0",
"connection": "close",
"content-encoding": "gzip",
"content-security-policy": "frame-ancestors 'self'",
"content-type": "application/json; charset=UTF-8",
"date": "Thu, 11 Jun 2020 17:39:49 GMT",
"expires": "Thu, 11 Jun 2020 17:39:49 GMT",
"server": "GSE",
"transfer-encoding": "chunked",
"vary": "Origin, X-Origin",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "1; mode=block"
},
"status": 404,
"statusText": "Not Found",
"request": {
"responseURL": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8"
}
},
"config": {
"url": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8",
"method": "GET",
"userAgentDirectives": [
{
"product": "google-api-nodejs-client",
"version": "4.3.0",
"comment": "gzip"
}
],
"headers": {
"x-goog-api-client": "gdcl/4.3.0 gl-node/12.16.3 auth/6.0.1",
"Accept-Encoding": "gzip",
"User-Agent": "google-api-nodejs-client/4.3.0 (gzip)",
"Authorization": "Bearer ya29.c.KpMBzgdYwb6AVurs1gP9fDRw4DMA1ys6ux77JueidiXXeloVDj0vw_hrAcu-souTl28QTrBIAYgz8OFqu7PUCwpy8NhUa2B5SyxYuoAJPAdtWm8dBYNw2xRLc6lK7F5t7cBye95H98B_lyZqeMQAj2p5w4xdxdps2HY7dpyEvNsiN2O_qugQSxzHHV-9NeBSZe0xHoD5",
"Accept": "application/json"
},
"params": {},
"retry": true,
"responseType": "json",
"retryConfig": {
"currentRetryAttempt": 0,
"retry": 3,
"httpMethodsToRetry": [
"GET",
"HEAD",
"PUT",
"OPTIONS",
"DELETE"
],
"noResponseRetries": 2,
"statusCodesToRetry": [
[
100,
199
],
[
429,
429
],
[
500,
599
]
]
}
},
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"stack": [
"Error: Not Found",
" at Gaxios._request (/var/task/node_modules/gaxios/build/src/gaxios.js:85:23)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)",
" at async JWT.requestAsync (/var/task/node_modules/google-auth-library/build/src/auth/oauth2client.js:342:22)",
" at async Runtime.exports.handler (/var/task/index.js:59:26)"
]
}
API Explorer with same CalendarId and EventId returns 200:
{
"kind": "calendar#event",
"etag": "\"3179827035790000\"",
"id": "irudvea992rumvho9eosunifq8",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=aXJ1ZHZlYTk5MnJ1bXZobzllb3N1bmlmcThfMjAyMDA1MThUMTUwMDAwWiBjb25uY29sbC5lZHVfMDIzaHM1aGN0NDF2aGhpYmFtamJhc2RrYnNAZw",
"created": "2020-02-16T19:15:21.000Z",
"updated": "2020-05-19T18:38:37.933Z",
"summary": "Lunch",
"creator": {
"email": "cw@conncoll.edu"
},
"organizer": {
"email": "conncoll.edu_023hs5hct41vhhibamjbasdkbs@group.calendar.google.com",
"displayName": "Harris Hours",
"self": true
},
"start": {
"dateTime": "2020-05-18T11:00:00-04:00",
"timeZone": "America/New_York"
},
"end": {
"dateTime": "2020-05-18T14:00:00-04:00",
"timeZone": "America/New_York"
},
"recurrence": [
"RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20200823;BYDAY=FR,MO,SA,TH,TU,WE"
],
"iCalUID": "irudvea992rumvho9eosunifq8@google.com",
"sequence": 1,
"reminders": {
"useDefault": false
}
}
Ok this is getting weird. Could I trouble you to try the code I posted above, with the latest googleapis
and @google-cloud/local-auth
modules?
Ran Sample code with 52.1.0
$ node server.js (node:49666) UnhandledPromiseRejectionWarning: Error: Not Found at Gaxios._request (/Users/atilling/Desktop/eventy/node_modules/gaxios/build/src/gaxios.js:85:23) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async OAuth2Client.requestAsync (/Users/atilling/Desktop/eventy/node_modules/google-auth-library/build/src/auth/oauth2client.js:342:22) at async main (/Users/atilling/Desktop/eventy/server.js:12:15) (node:49666) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag
--unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:49666) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I ran it exactly as posted. I'll rerun shortly with cal and event ids i as trying to query
Using my calendarId and eventId I am getting a result using the provided code. Is it possible it is an issue with OAuth2 vs a service account?
This is the code I'm using that is failing
'use strict'
const privatekey = require("./camelwebKey.json");
const {google} = require('./node_modules/googleapis/build/src');
let message;
let calId;
let eventId;
let eventDate;
exports.handler = async (event) => {
try{
calId = "conncoll.edu_ungnu8i9cf8ntcrm2vtho3ums0@group.calendar.google.com";
if(event && event.locationID){
if (event['locationID'] == 'Harris'){
calId = "conncoll.edu_023hs5hct41vhhibamjbasdkbs@group.calendar.google.com";
}
}if(event && event.eventID){
eventId = event['eventID'];
eventDate = eventId.substring(eventId.indexOf('|')+1,eventId.indexOf('|')+9);
eventId = eventId.substring(0,eventId.indexOf('@'));
}
console.log ("CalId: "+calId);
console.log ("EventId: "+eventId);
console.log ("EventDate: "+eventDate);
// configure a JWT auth client
let jwtClient = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events']);
//authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err);
return;
} else {
console.log("Successfully connected!");
}
});
const cal = google.calendar('v3');
let folderList =[];
let fconf = {};
fconf.auth = jwtClient;
fconf.calendarId = calId;
fconf.eventId = eventId;
const calEvent = await cal.events.get(fconf);
console.log (calEvent);
message = calEvent.data;
} catch (err) {
console.log(err);
return err;
}
return message
};
Ah! Let's focus on this right here: https://github.com/googleapis/google-api-nodejs-client/issues/2229#issuecomment-643341516
I don't have a service account with access to a calendar on hand, so I have to try this blind 😆 Can you give something like this a shot?
const path = require('path');
const {google} = require('googleapis');
async function main() {
const auth = new google.auth.JWT({
scopes: ['https://www.googleapis.com/auth/calendar'],
keyFile: path.resolve('../keys/jwt.keys.json'),
});
google.options({auth});
const calendar = google.calendar('v3');
const res = await calendar.events.get({
calendarId: '<YOUR_CALENDAR_ID',
eventId: 'YOUR_EVENT_ID',
});
console.log(res.data);
}
main();
I'm trying to distill this down to the minimum code to reproduce things :)
Greetings, we're closing this due to inactivity. Please let us know if the issue needs to be reopened.
Environment details
googleapis
version: googleapis@39.2.0Steps to reproduce
calId: conncoll.edu_023hs5hct41vhhibamjbasdkbs@group.calendar.google.com eventId: irudvea992rumvho9eosunifq8
Return as follows, note the url has %40 if the URL is sent as @ and not %40 the return is correct