I have a requirement to get the most recent activity for each user in the domain within Google Currents (formerly, Google plus)
I am using AdminReports.Activities.list for this, using the 'all' parameter rather than an email address.
I have tested with the following script:
function testFunc() {
let target;
if (testState == true) {
target = "single.user@email.com";
} else if (testState == false) {
target = "all";
} else {
throw "State not defined";
}
const app = "gplus";
const daysToCheck = 1;
const now = new Date();
const daysAgo = new Date(now.getTime() - daysToCheck * 24 * 60 * 60 * 1000);
const date = daysAgo.toISOString();
const optionalArgs = {
startTime: date
};
let rows = [];
let response;
let pageToken;
do {
response = AdminReports.Activities.list(target, app, optionalArgs);
let activities = response.items;
if (activities) {
activities.forEach(item => {
let row = [
new Date(item.id.time),
item.actor.email,
item.events[0].name
]
rows.push(row)
})
} else {
throw 'Error'
}
pageToken = response.nextPageToken;
} while (pageToken);
Logger.log(rows);
/** NOTES
* will eventually log this out to a spreadsheet
*/
}
However, this will return multiple events for a single person. I need to only return the most recent event for each user in the domain.
Does anyone have any ideas on how to achieve this?