Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json Key or Pem Key error #39

Open
Nathan9745354 opened this issue Apr 7, 2021 · 8 comments
Open

Json Key or Pem Key error #39

Nathan9745354 opened this issue Apr 7, 2021 · 8 comments

Comments

@Nathan9745354
Copy link

Nathan9745354 commented Apr 7, 2021

This is PEM error
listBookedEventsByRoom Error: Error: failed to obtain an authentication token, request failed with HTTP code 400: invalid_grant
listEmptySlotsInDay Error: Error: failed to obtain an authentication token, request failed with HTTP code 400: invalid_grant

Json Key error
listBookedEventsByRoom Error: Error: failed to sign JWT, the key is probably invalid
listEmptySlotsInDay Error: Error: failed to sign JWT, the key is probably invalid

Code here:
Settings.js

//require the Google API Json Key
const KEYFILE = '../data/xxxxxx-xxxxxxxxx.pem';
const SERVICE_ACCT_ID = [email protected]';
const CALENDAR_URL = 'https://calendar.google.com/calendar/embed?src=xxxxxxxxgmail.com&ctz=Asia%2FHong_Kong';
const CALENDAR_ID={"primary": "[email protected]","th":"[email protected]","ko":[email protected]","kc":"[email protected]","hl":"[email protected]","ml":"[email protected]","fg":"[email protected]","q1":[email protected]","q2":"[email protected]","qc":[email protected]","dr":[email protected]","bb":"[email protected]","tt":"[email protected]","mc":"[email protected]","ak":"[email protected]","sk":"[email protected]","zk":"[email protected]"
};
const TIMEZONE = 'UTC+08:00';

module.exports.calendarUrl = CALENDAR_URL;
module.exports.serviceAcctId = SERVICE_ACCT_ID;
module.exports.calendarId = CALENDAR_ID;
module.exports.keyFile = KEYFILE;
module.exports.timezone = TIMEZONE;

//To use, require the module in your application and pass in the necessary config file.
/const CONFIG = require('./config/settings.js');
const CalendarAPI = require('node-google-calendar');
let cal = new CalendarAPI(CONFIG);
/

export { CONFIG as default, ROOM_CONFIG, SESSION_LENGTH, BOOKING_DURATION_OPTIONS };
`

.env file:

TELEGRAM_BOT_TOKEN=xxxxxxxxxxxxxxxxxttl_xxxxxxxxxxxxxx [email protected] CALENDAR_ID={"primary": "[email protected]","th":"[email protected]","ko":[email protected]","kc":"[email protected]","hl":"[email protected]","ml":"[email protected]","fg":"[email protected]","q1":[email protected]","q2":"[email protected]","qc":[email protected]","dr":[email protected]","bb":"[email protected]","tt":"[email protected]","mc":"[email protected]","ak":"[email protected]","sk":"[email protected]","zk":"[email protected]" }; CALENDAR_URL=https://calendar.google.com/calendar/embed?src=xxxxx%40gmail.com&ctz=Asia%2FHong_Kong GOOGLE_KEYFILE_PATH=../data/xxxx-xxxx.pem

Please Help Thanks!!

@languantan
Copy link
Contributor

languantan commented Apr 8, 2021 via email

@Nathan9745354
Copy link
Author

Hi Languantan,

Yes,
I did create a service account on google cloud console and generated json key and pem key, the step ( go to google cloud console and selectd Service account and created one account then selected that account and click key, create one key and selected json key. I was put json key and pem key to data and (.env) file set config like GOOGLE_KEYFILE_PATH=../data/abc123-xxxx.pem then ran "npm start" but got above error, as the same method with pem, set the json key to {.env) and went to settings.js like

Settings.js
`const key = require('../data/tghkbooking-d78bff29d190.json').private_key;
const SERVICE_ACCT_ID = [email protected]';
const CALENDAR_URL = 'https://calendar.google.com/calendar/embed?src=xxxxxxxxgmail.com&ctz=Asia%2FHong_Kong';
const CALENDAR_ID={"primary": "[email protected]","th":"[email protected]","ko":[email protected]","kc":"[email protected]","hl":"[email protected]","ml":"[email protected]","fg":"[email protected]","q1":[email protected]","q2":"[email protected]","qc":[email protected]","dr":[email protected]","bb":"[email protected]","tt":"[email protected]","mc":"[email protected]","ak":"[email protected]","sk":"[email protected]","zk":"[email protected]"
};
const TIMEZONE = 'UTC+08:00';

module.exports.calendarUrl = CALENDAR_URL;
module.exports.serviceAcctId = SERVICE_ACCT_ID;
module.exports.calendarId = CALENDAR_ID;
module.exports.key = key;
module.exports.timezone = TIMEZONE;

//To use, require the module in your application and pass in the necessary config file.
/const CONFIG = require('./config/settings.js');
const CalendarAPI = require('node-google-calendar');
let cal = new CalendarAPI(CONFIG);/

export { CONFIG as default, ROOM_CONFIG, SESSION_LENGTH, BOOKING_DURATION_OPTIONS };`

.env
TELEGRAM_BOT_TOKEN=xxxxxxxxxxxxxxxxxttl_xxxxxxxxxxxxxx SERVICE_ACCT_ID=[email protected] CALENDAR_ID={"primary": "[email protected]","th":"[email protected]","ko":[email protected]","kc":"[email protected]","hl":"[email protected]","ml":"[email protected]","fg":"[email protected]","q1":[email protected]","q2":"[email protected]","qc":[email protected]","dr":[email protected]","bb":"[email protected]","tt":"[email protected]","mc":"[email protected]","ak":"[email protected]","sk":"[email protected]","zk":"[email protected]" }; CALENDAR_URL=https://calendar.google.com/calendar/embed?src=xxxxx%40gmail.com&ctz=Asia%2FHong_Kong GOOGLE_KEYFILE_PATH=../data/xxxx-xxxxxx.json

@Nathan9745354
Copy link
Author

This should be the same Google account as which the Google calendars (for
each room) are created in. You can find more information

what mean Google account as which the Google calendars (for
each room)?

I am using differ Google calendars account. I created a new gmail.

For example: my google cloud account is [email protected] but in google calendar as using [email protected] for each room.

@languantan
Copy link
Contributor

languantan commented Apr 8, 2021 via email

@Nathan9745354
Copy link
Author

You mention the Google API Key is saying Json Key generated from service account?

I'm not confirm the API Key has access right to Google Calendar.

In Google Cloud has enable API Calendar . But how can I test the Json key can accessible?

@Nathan9745354
Copy link
Author

Do I need setting Oauth2.0 and create an application for API Key access Calendar?

https://developers.google.com/calendar/auth

@Nathan9745354
Copy link
Author

Nathan9745354 commented Apr 8, 2021

Update: I am using this URL to confirm.
API KEY:https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=AIzaSyCP3DPfq4CaXXXXXXXXXXXXXXXXX

And I got this but it is not Json Key.
{
"kind": "calendar#events",
"etag": ""p33ccj77lijmeu0g"",
"summary": "Primary",
"updated": "2021-04-07T12:45:35.863Z",
"timeZone": "Asia/Hong_Kong",
"accessRole": "reader",
"defaultReminders": [],
"nextSyncToken": "CNjJnPWU7O8CEAxxxxxxxxx==",
"items": []
}

@Nathan9745354
Copy link
Author

any suggestions? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants