Using the following apps script function i can successfully create folders in google drive:
function uploadFileToGoogleDrive(data, file, name, email) {
var parentFolderId = "FOLDER_ID";
var parentFolder = DriveApp.getFolderById(parentFolderId);
var subfolder;
try {
subfolder = parentFolder.getFoldersByName([name, email].join(" ")).next();
}
catch(e) {
subfolder = parentFolder.createFolder([name, email].join(" "));
}
var contentType = data.substring(5,data.indexOf(';')),
bytes = Utilities.base64Decode(data.substr(data.indexOf('base64,')+7)),
blob = Utilities.newBlob(bytes, contentType, file),
file = subfolder.createFile(blob);
file = subfolder.createFile(file, data);
Logger.log(subfolder);
return "OK";
}
i want to access the folder using the following script:
function downloadFile(e) {
var parentFolderId = "FOLDER_ID";
var parentFolder = DriveApp.getFolderById(parentFolderId);
var subfolderId;
var subfolders = parentFolder.getFoldersByName([name, email].join(" "));
while (subfolders.hasNext()) {
var folder = subfolders.next();
Logger.log(folder.getId());
}
}
appsscript.json for uploadFileToGoogleDrive:
{
"timeZone": "Europe/Bucharest",
"dependencies": {
},
"webapp": {
"access": "ANYONE_ANONYMOUS",
"executeAs": "USER_DEPLOYING"
},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8"
}
appsscript.json for downloadFile :
{
"timeZone": "Europe/Bucharest",
"dependencies": {
},
"webapp": {
"access": "ANYONE_ANONYMOUS",
"executeAs": "USER_DEPLOYING"
},
"exceptionLogging": "STACKDRIVER",
"oauthScopes": ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/drive.readonly"],
"runtimeVersion": "V8"
}
The script can access ONLY the folders Created with google drive Web! But cannot get the folders created with other apps script.
Note that the two functions (upload and download) are in separate google apps scripts.
https://www.googleapis.com/auth/drive.readonly
andhttps://www.googleapis.com/auth/drive
are granted for the second script, but when i grant the first it stops working. 2. there is no error, the script keeps waiting for logs – user3140792Logger.log(subfolders.hasNext())
before calling it inwhile
– TheMaster