The Google Calender Node.js example requires a file called "credentials.json": https://developers.google.com/calendar/quickstart/nodejs
Relevant code:
// Load client secrets from a local file.
fs.readFile('credentials.json', (err, content) => {
if (err) return console.log('Error loading client secret file:', err);
// Authorize a client with credentials, then call the Google Calendar API.
authorize(JSON.parse(content), listEvents);
});
function authorize(credentials, callback) {
const {client_secret, client_id, redirect_uris} = credentials.installed;
const oAuth2Client = new google.auth.OAuth2(
client_id, client_secret, redirect_uris[0]);
// Check if we have previously stored a token.
fs.readFile(TOKEN_PATH, (err, token) => {
if (err) return getAccessToken(oAuth2Client, callback);
oAuth2Client.setCredentials(JSON.parse(token));
callback(oAuth2Client);
});
}
I don't know where to find this file. The Google API console offers a "download JSON" option, but the file is not in the right format and it is missing the redirect_uris
field.
credentials.json
file for using Google API with Quickstart of Node.js.If my understanding is correct, how about this answer? Please think of this as just one of several answers.
In this answer, it supposes that you clicked "Enable the Google Calendar API" button.
When you click "Enable the Google Calendar API" button, the following screen can be seen. Here, please click "API console".
When you click "API console", the following screen can be seen. Here, please click "Credentials".
When you click "Credentials", the following screen can be seen. Here, please click the download button. By this, you can retrieve the JSON file. At this time, please rename the file to credentials.json
, and put it to the directory with the path for using at Quickstart of Node.js.
If I misunderstood your question and this was not the direction you want, I apologize.