In March 2022, Google announced autogenerated summaries for some documents, alongside the document outline. I'm wondering if there's a way to access these summaries in gas, e.g. via DocumentApp.
In the current stage, in order to retrieve the document summary, you can retrieve it using Drive API as follows.
GET https://www.googleapis.com/drive/v3/files/fileId?fields=description
The sample Google Apps Script is as follows. When you use this, please enable Drive API at Advanced Google services.
const documentId = "###"; // Please set Document ID.
const summary = Drive.Files.get(documentId).description;
console.log(summary)
When this script is run, the summary text of Google Document can be retrieved.
In this case, you can also use Drive service (DriveApp) as follows.
const documentId = "###"; // Please set Document ID.
const summary = DriveApp.getFileById(documentId).getDescription();
console.log(summary)
In order to retrieve the document summary, you can put it using Drive API as follows.
PATCH https://www.googleapis.com/drive/v3/files/fileId
content-type: application/json
{"description": "sample summary text"}
The sample Google Apps Script is as follows. When you use this, please enable Drive API at Advanced Google services.
const documentId = "###"; // Please set Document ID.
const summary = "sample summary";
Drive.Files.patch({description: summary}, documentId);
When this script is run, the summary text can be put to Google Document.
In this case, you can also use Drive service (DriveApp) as follows.
const documentId = "###"; // Please set Document ID.
const summary = "sample summary";
DriveApp.getFileById(documentId).setDescription(summary);