0
votes

I am writing a web app that will allow students to click a button to create a set of folders & files in their own drive taken from a spreadsheet. My problem is that for some reason when anyone else clicks on the button in the web app, the folder is always made in my own drive, and never the students!

edit: it recognizes the correct user as the active user but still creates the file in my drive not theirs

I've made apps like this before that copied files (not folders) into the user's Drive, and those work fine, but for some reason this doesn't. Is it because I'm creating a brand new folder instead of copying it? The web apps i'd created before always asked the user for permission to look at their drive & edit folders etc but this one doesn't. I can't figure out what I'm doing wrong. Any ideas?

I even tried setting the ownership to the user but it still gets created in my own drive it's driving me nuts. Is there a way to move a folder into a user's my drive through apps script? I couldn't find it in the documentation.

var sheet = '1kM7GeBubLRDC_L_G0rrlddHARSL59DkmWco6Z72gJAg';
var ss = SpreadsheetApp.openById(sheet).getActiveSheet();   //SPREADSHEET


var netID = Session.getActiveUser();        
var title = ss.getRange("D1").getValue();


var mainFolder = DriveApp.createFolder(title);
var mainFolderID = mainFolder.getId();
var portfolio = DriveApp.getFolderById(mainFolderID);
portfolio.setOwner(netID + "@nyu.edu");
Logger.log(getOwner(portfolio));
1

1 Answers

0
votes

The problem here is with how the script is published, you have it set up to execute as you, so the items are created on your drive.

Under the "Deploy as a web app..." settings check the option "Execute the app as" , the value needs to be "User accessing the web app" instead of "Me".

See: https://developers.google.com/apps-script/guides/web#deploying_a_script_as_a_web_app