Get Google Drive Activity Using Google Apps Script

2019-08-10 19:50发布

Problem:- List all the files in google drive which were modified in last 24 hours.

Tried the following:- * Used DocsList API to get the files under a folder, based on the last modified time, able to identify the files which were modified.

Problems Facing:- There are many folders/sub folders in my drive, when am processing all the folders recursively script taking longer time and getting timed out.

Alternative:- In the Google Drive, there's a field called Activity, which will show the recent activity.

Is this possible to get the Activity from google drive using API(DocsList, GoogleDrive,other? If Yes, please let me know the details.

Also, if there are other solutions please let me know.

Thanks in adance...

2条回答
男人必须洒脱
2楼-- · 2019-08-10 20:44

I realize this is an old question and I am not certain this was even possible when it was asked, but it is fairly straightforward with the DriveApp service now.

function listRecentFiles() {
  var ageInHours = 24;
  var targetDate = new Date;
  targetDate.setHours( targetDate.getHours() - ageInHours );
  var q = 'modifiedDate > "' + targetDate.toISOString() + '"';

  var files = DriveApp.searchFiles(q);

  while( files.hasNext() ) {
    var file = files.next();
    Logger.log(file.getName());
  }
}

Reference:

https://developers.google.com/apps-script/reference/drive/drive-app#searchFiles(String) https://developers.google.com/drive/web/search-parameters

查看更多
Lonely孤独者°
3楼-- · 2019-08-10 20:52

Check out the change feed: https://developers.google.com/drive/manage-changes

The is a part of the Drive SDK, which allows you to request all changes that have occurred since a particular change id.

查看更多
登录 后发表回答