32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
const apiKey = 'AIzaSyBOCClHTZU9e38VLDljXR-O4QVtk1gCZ1k';
|
|
const calendars = {
|
|
'MURILO AMORIM': 'muriloamorim791@gmail.com',
|
|
'RUI CESAR VARGAS': 'ruibto@gmail.com'
|
|
};
|
|
|
|
async function testGoogleApi() {
|
|
const timeMin = new Date().toISOString();
|
|
|
|
for (const [name, id] of Object.entries(calendars)) {
|
|
console.log(`Checking ${name} (${id})...`);
|
|
try {
|
|
const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(id)}/events?key=${apiKey}&timeMin=${timeMin}&singleEvents=true&orderBy=startTime`;
|
|
const response = await fetch(url);
|
|
const data = await response.json();
|
|
|
|
if (data.error) {
|
|
console.log(` ERROR: ${data.error.message}`);
|
|
if (data.error.message === 'Not Found') {
|
|
console.log(` HINT: The calendar might not be PUBLIC or the ID is wrong.`);
|
|
}
|
|
} else {
|
|
console.log(` SUCCESS: Found ${data.items ? data.items.length : 0} events.`);
|
|
}
|
|
} catch (err) {
|
|
console.log(` FETCH FAILED: ${err.message}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
testGoogleApi();
|