-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGS_GetData.gs
More file actions
49 lines (37 loc) · 1.2 KB
/
Copy pathGS_GetData.gs
File metadata and controls
49 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function getFileData(scriptId,theAccessTkn) {
var errMsg,files,options,payload,response,url;
if (!scriptId) {
Logger.log('There was an error - No scriptID')
//Error handling function
return;
}
if (!theAccessTkn) {
theAccessTkn = ScriptApp.getOAuthToken();
}
//This is exactly the same URL that is used to update content - But this uses a GET request
//and no payload
url = "https://script.googleapis.com/v1/projects/" + scriptId + "/content";
options = {
"method" : "GET",
"muteHttpExceptions": true,
"headers": {
'Authorization': 'Bearer ' + theAccessTkn
}
};
response = UrlFetchApp.fetch(url,options);
//Logger.log('response 27: ' + response)
response = JSON.parse(response);//The response must be parsed into JSON even though it is an object
if (typeof response === 'object') {
errMsg = response.error;
if (errMsg) {
errMsg = errMsg.message;
return 'err' + errMsg;
}
}
files = response.files;//Get only the files out of the object
//Logger.log("files 31: " + JSON.stringify(files))
return files;
}
function testGetFiles() {
getFiles("170wz-l3jR6QEJKs-R-FXrOIUmk_gNfuHvyblEJdbwZLnzf-h8RjsnO0t");
}