this is a continuation of my previous question in which @Lorena proposed a very good solution to get Google Meets Call record data using Google Apps Script, here is the code snippet:
function getMeetLogs() {
const userKey = 'test@domain.xyz';// Replace with the desired user's email address
const applicationName = 'meet';
var duration = [];
var meets = [];
var options = {eventName: "call_ended"};
var meetLogs = AdminReports.Activities.list(userKey, applicationName, options);
for (var i = 0; i < meetLogs.items.length; i++) {
var date = new Date(meetLogs.items[i].id.time);
var month = date.getMonth() + 1;
var param = meetLogs.items[i].events[0].parameters;
//console.log(param)//here you can see all the event details
if (month == 5) {//change 5 to the month number you're looking for
//For each event, iterate and to determine the call duration if the event name is duration_seconds
for (var j = 0; j < param.length; j++) {
if (param[j].name == 'meeting_code') {
meets.push(param[j].value)
}
if (param[j].name == 'duration_seconds') {
duration.push(parseInt(param[j].intValue))
}
}
}
}
//Counting unique meetings to avoid counting duplicate meet codes (recurring meetings have the same meeting code)
let uniqueMeets = [...new Set(meets)].length
let sum = 0;
duration.forEach(num => {
sum += num;
})
console.log("Total calls for user " + userKey + ": " + uniqueMeets)
console.log("Total minutes in call for user " + userKey + ": " + sum/60)
}
It has been running perfectly until now, but now it shows this error whenever I run it:
GoogleJsonResponseException: API call to reports.activities.list failed with error: Request had insufficient authentication scopes
I have tried adding various scopes in appsscript.json file but to no avail:
"oauthScopes": [
"https://www.googleapis.com/auth/admin.directory.user",
"https://www.googleapis.com/auth/admin.directory.user.readonly",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/spreadsheets.currentonly",
"https://www.googleapis.com/auth/spreadsheets"
]
Any guidance on where the issue might be, thank you for your assistance.
GoogleJsonResponseException: API call to reports.activities.list failed with error: Request had insufficient authentication scopes
This message means that the authentication credentials for the user you have logged in do not contain the permissions that you need to provide.
Determine which method you are trying to call that is resulting in this message check the documentation to ensure that you are requesting the correct scopes. Then reauthenticate the user.
The above API call requires the following OAuth scope: https://www.googleapis.com/auth/admin.reports.audit.readonly
Note: Remember if you have changed your code you need to force the user to reauthenticate.