使用 App 脚本访问完整的 google 日志
using App script to access full google logs
我正在编写一个脚本来审核完整的 google 日志。 Google 保留 450 天(14.7 个月)的日志,但它们仅在控制台中提供 6 个月的日志,因此我正在编写一个脚本以提取完整的 14.7 个月。我联系了 google 支持人员以了解如何最好地做到这一点,他们建议使用 api 调用。
https://developers.google.com/admin-sdk/reports/v1/reference/userUsageReport
我有一个现在可以使用 6 个月的脚本,但我不确定如何将它延长到 google 记录的完整 14 个月。我尝试更改开始日期,但看起来可能更复杂。
function getData () {
var now = new Date();
var fourhundredfiftydaysago = new Date(now.getTime() - 1000 * 60 * 60 * 24 * 450);
var startTime= fourhundredfiftydaysago.toISOString();
var apps_list = ['admin', 'calendar', 'drive', 'groups', 'gplus', 'login', 'mobile', 'rules', 'token'];
var userKey = 'all';
var optionalArgs = {startTime: startTime};
for (i = 0; i < apps_list.length; i++){
var applicationName = apps_list[i];
var response = AdminReports.Activities.list(userKey, applicationName, optionalArgs)
var activities = response.items;
if (activities && activities.length > 0) {
Logger.log(apps_list[i] + ':');
for (x = 0; x < activities.length; x++) {
var activity = activities[x];
Logger.log('%s: %s (%s)', activity.id.time, activity.actor.email, activity.events[0].name, activity.ipAddress);
}
}
else {
Logger.log(apps_list[i] + ':')
Logger.log('No logs found.');
}
}
}
在您的示例中,您查询的是 AdminReports.Activites
而不是 AdminReports.UserUsageReports
。
后者是您链接到的文档。如果您查看 the documentation for AdminReports.Activities
,所有申请报告的最长期限均为 180 天。
我正在编写一个脚本来审核完整的 google 日志。 Google 保留 450 天(14.7 个月)的日志,但它们仅在控制台中提供 6 个月的日志,因此我正在编写一个脚本以提取完整的 14.7 个月。我联系了 google 支持人员以了解如何最好地做到这一点,他们建议使用 api 调用。
https://developers.google.com/admin-sdk/reports/v1/reference/userUsageReport
我有一个现在可以使用 6 个月的脚本,但我不确定如何将它延长到 google 记录的完整 14 个月。我尝试更改开始日期,但看起来可能更复杂。
function getData () {
var now = new Date();
var fourhundredfiftydaysago = new Date(now.getTime() - 1000 * 60 * 60 * 24 * 450);
var startTime= fourhundredfiftydaysago.toISOString();
var apps_list = ['admin', 'calendar', 'drive', 'groups', 'gplus', 'login', 'mobile', 'rules', 'token'];
var userKey = 'all';
var optionalArgs = {startTime: startTime};
for (i = 0; i < apps_list.length; i++){
var applicationName = apps_list[i];
var response = AdminReports.Activities.list(userKey, applicationName, optionalArgs)
var activities = response.items;
if (activities && activities.length > 0) {
Logger.log(apps_list[i] + ':');
for (x = 0; x < activities.length; x++) {
var activity = activities[x];
Logger.log('%s: %s (%s)', activity.id.time, activity.actor.email, activity.events[0].name, activity.ipAddress);
}
}
else {
Logger.log(apps_list[i] + ':')
Logger.log('No logs found.');
}
}
}
在您的示例中,您查询的是 AdminReports.Activites
而不是 AdminReports.UserUsageReports
。
后者是您链接到的文档。如果您查看 the documentation for AdminReports.Activities
,所有申请报告的最长期限均为 180 天。