Get all properties from Drive.Revision
Have you ever found yourself trying to retrieve data from Drive.Revision
, specifically properties like publishedLink
, and wondered why it wasn't there? The solution is simpler than you might think!
To optimize API call speed and reduce bandwidth usage, Drive.Revision.get()
in Apps Script returns only a subset of properties by default. Unfortunately, there are no hidden options within the standard Apps Script methods to request all properties.
However, you can leverage the power of the Drive REST API directly from within your Apps Script project.
1try {
2const token = ScriptApp.getOAuthToken();
3
4 // ?fields=* means all fields, if you only want one or a few, just list them
5 const apiUrl = `https://www.googleapis.com/drive/v2/files/${docId}/revisions/${revisionId}?fields=*`;
6
7
8 const apiOptions = {
9 method: 'get',
10 headers: {
11 'Authorization': 'Bearer ' + token
12 },
13 contentType: 'application/json',
14 muteHttpExceptions: true // For error handling
15 };
16
17
18 const response = UrlFetchApp.fetch(apiUrl, apiOptions);
19 const responseCode = response.getResponseCode();
20 const responseBody = response.getContentText();
21
22
23 if (responseCode === 200) {
24 const revisionDetails = JSON.parse(responseBody);
25 const publishedUrl = revisionDetails.publishedLink;
26
27
28 if (publishedUrl) {
29 Logger.log(`[${functionName}] Got publishedUrl: ${publishedUrl}`);
30 return publishedUrl;
31 } else {
32 Logger.log(`[${functionName}] API call failed with error code ${responseCode}: ${responseBody}`);
33 }
34
35
36 } catch (e) {
37 Logger.log(`[${functionName}] Critical error: ${e.toString()}`);
38 }