Created
April 11, 2024 18:13
-
-
Save battis/2f24081dd024cd743a752dd21e84722b to your computer and use it in GitHub Desktop.
Get content of user-attributed revision to a Google Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Seth Battis | |
* Google Apps Script | |
* No external dependencies | |
*/ | |
/** | |
* @param fileId: string - Google Sheets document ID | |
* @param tileIndex: number - index of "combined revisions" shown in versions UI | |
*/ | |
function test(fileId, tileIndex) { | |
const tiles = getRevisionTiles(fileId) | |
Logger.log(`Revision "Tile" ${tileIndex}, Changes by ${tiles.tileInfo[tileIndex].users.map(id => tiles.userMap[id].name).join(', ')}`) | |
Logger.log(getRevisionComparision(fileId, tiles.tileInfo[tileIndex].end, tiles.tileInfo[tileIndex].start)) | |
} | |
function getRevisionTiles(fileId) { | |
return JSON.parse(UrlFetchApp.fetch(`https://docs.google.com/spreadsheets/d/${fileId}/revisions/tiles?id=${fileId}&start=1&revisionBatchSize=1500&showDetailedRevisions=false&loadType=0&includes_info_params=true&cros_files=false`, { | |
headers: { | |
Authorization: `Bearer ${ScriptApp.getOAuthToken()}` | |
} | |
}).getContentText().substring(4)) | |
} | |
function getRevisionComparision(fileId, revisionId, previousRevisionId) { | |
return UrlFetchApp.fetch(`https://docs.google.com/spreadsheets/d/${fileId}/revisions/show?includes_info_params=true&cros_files=false&rev=${revisionId}&fromRev=${previousRevisionId}`, { | |
headers: { | |
Authorization: `Bearer ${ScriptApp.getOAuthToken()}` | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment