Skip to content

Instantly share code, notes, and snippets.

@battis
Created April 11, 2024 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/2f24081dd024cd743a752dd21e84722b to your computer and use it in GitHub Desktop.
Save battis/2f24081dd024cd743a752dd21e84722b to your computer and use it in GitHub Desktop.
Get content of user-attributed revision to a Google Sheet
/*
* 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