Json Key or Pem Key error
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!!
Hi,
As the comment says in the config, you will need to create a Service Account and get a Google API Key in p12 format.
This should be the same Google account as which the Google calendars (for each room) are created in. You can find more information https://cloud.google.com/iam/docs/creating-managing-service-account-keys.
On Thu, 8 Apr 2021, 3:46 am Nathan9745354, @.***> wrote:
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/tghkbooking-xxxxxxxxx.pem'; const SERVICE_ACCT_ID = @.'; const CALENDAR_URL = ' https://calendar.google.com/calendar/embed?src=xxxxxxxxgmail.com&ctz=Asia%2FHong_Kong '; const CALENDAR_ID={"primary": @.@.","ko": @.@.@.@.*** @.@.@.","qc": @.@.@.@.*** @.@.@.","zk":" @." }; 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 }; `
Please Help Thanks!!
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GovTechSG/butler-bot/issues/39, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA74UPBEOPIELQ45JO32Z6DTHSZBZANCNFSM42RNNXKA .
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 [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
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.
Hmm I suspect your Google API key does not have access to your calendar. Anyway you can confirm the API key has access?
On Thu, 8 Apr 2021, 3:51 pm Nathan9745354, @.***> wrote:
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 @.*** but in google calendar as using @.*** for each room.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GovTechSG/butler-bot/issues/39#issuecomment-815537891, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA74UPDJ7VMTD5LIWB4YCBTTHVN6RANCNFSM42RNNXKA .
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?
Do I need setting Oauth2.0 and create an application for API Key access Calendar?
https://developers.google.com/calendar/auth
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": [] }
any suggestions? Thanks