Google Drive Activity Service

The Google Drive Activity service allows you to use the Google Drive Activity API in Apps Script. This API allows users programmatic access to retrieve information about their Google Apps activity.

Reference

For detailed information on this service, see the reference documentation for the Google Drive Activity API. Like all advanced services in Apps Script, the Google Drive Activity service uses the same objects, methods, and parameters as the public API.

To report issues and find other support, see the Google Drive Activity support guide.

Sample code

The sample code below uses version 1 of the API.

Get a file's activity

This sample gets a file's activity and logs the list of unique users that performed the activity.

advanced/driveActivity.gs
/**
 * Gets a file's activity and logs the list of
 * unique users that performed the activity.
 */
function getUsersActivity() {
  var fileId = 'YOUR_FILE_ID_HERE';

  var pageToken;
  var users = {};
  do {
    var result = AppsActivity.Activities.list({
      'drive.fileId': fileId,
      'source': 'drive.google.com',
      'pageToken': pageToken,
    });
    var activities = result.activities;
    for (var i = 0; i < activities.length; i++) {
      var events = activities[i].singleEvents;
      for (var j = 0; j < events.length; j++) {
        var event = events[j];
        users[event.user.name] = true;
      }
    }
    pageToken = result.nextPageToken;
  } while (pageToken);
  Logger.log(Object.keys(users));
}

发送以下问题的反馈:

此网页
Apps Script
Apps Script
需要帮助?请访问我们的支持页面