If you want to play around with your scripts from within Apps Script, you’ll need to use the drive SDK. Although Drive is available as a Google Apps Script advanced service, the SDK is not – so we have to use the REST API to do stuff from.
Authentication
Drive SDK
info: { name: "cDbAbstraction", version: "2.0.3", key: "MHfCjPQlweartW45xYs6hFai_d-phDA33" } info: { name: "cUseful", version: "2.02", key: "Mcbr-v4SsYKJP7JMohttAZyz3TLx7pV4j" } info: { name: "cDriverSheet", version: "2.01", key: "Mrckbr9_w7PCphJtOzhzA_Cz3TLx7pV4j" }
Click on the button below to get all keys and dependencies from the majority of my public libraries.
function scriptExample () { // this will get an access token and pass it to doTheWork() return doGetPattern({} , constructConsentScreen, scriptTest,'script'); } function scriptTest (accessToken) { var options = { method: "GET", muteHttpExceptions: true, headers: { authorization: "Bearer " + accessToken } }; var url = "https://www.googleapis.com/drive/v2/files?q=" + encodeURIComponent("mimeType='application/vnd.google-apps.script' and 'me' in owners") ; var result = UrlFetchApp.fetch(url, options); var data = JSON.parse(result.getContentText()); // open a spreadsheet as a database var handler = new cDbAbstraction.DbAbstraction(cDriverSheet, { "siloid": "scripts", "dbid": "1yTQFdN_O2nFb9obm7AHCTmPKpf5cwAd78uNQJiCcjPk" }); if (!handler.isHappy()) throw 'could not open sheet'; // remove anything already there var result = handler.remove(); if (handler.handleCode < 0) throw JSON.stringify(result); // sort and log results var result = handler.save(data.items); if (handler.handleCode < 0) throw JSON.stringify(result); }
That gives a massive sheet, which starts like this
Now let’s head over to Drive JSON API for apps script for a more detailed dive into cool things you can do with the SDK and your scripts
For help and more information join our community, follow the blog or follow me on Twitter