0

Is it possible to get the shared date of a file in GAS? It is possible to get a list of files shared with me in the drive by the following code:

var files = DriveApp.searchFiles("sharedWithMe");

But the iterator returns a list of files sorted according to the last modified date. I want the list of files sorted in the "shared date" order. If that is not possible is it in the least possible to get the shared date of a given file in google drive? I have looked through the documentations of the File and the Search for Files and have searched on the net to no avail.

Riyafa Abdul Hameed
  • 7,417
  • 6
  • 40
  • 55

1 Answers1

1

You can retrieve the shared date using Drive API v2. "Drive API v2" can be used at Google Apps Script by enabling Drive API of Advanced Google services and of Google API Console.

How to use it is as follows.

  1. In the script editor, select Resources > Advanced Google services

  2. In the dialog that appears, click the on/off switch for Drive API v2.

  3. At the bottom of the dialog, click the link for the Google API Console.

  4. In the console, click into the filter box and type part of the name of the API "Drive API", then click the name once you see it.

  5. On the next screen, click Enable API.

  6. Close the Developers Console and return to the script editor. Click OK in the dialog. The advanced service you enabled is now available in autocomplete.

The detail information is https://developers.google.com/apps-script/guides/services/advanced.

At the sample script, it searches "sharedWithMe" using q and displays file ID, file name, shared date and share using fields. They are displayed by JSON. If the response is no data, it indicates there are no sharedwithme files.

Script :

var res = Drive.Files.list({
    q:      "sharedWithMe",
    fields: "items(id,shared,sharedWithMeDate,title)"
});
Logger.log(JSON.stringify(res))

Result :

{
  "items": [
    {
      "id": "#####",
      "sharedWithMeDate": "Time that the file was shared with the user",
      "shared": true,
      "title": "File name"
    }
  ]
}
Tanaike
  • 181,128
  • 11
  • 97
  • 165