I have created a google spreadsheet using web-apps-script and want to assign it a view-only access.
how can I do so I tried many different method but it does not work and keeps giving me errors.
I want any method to share my file to other user either by getting a shareable link or adding it into a public folder.
First I tried sharing it using script but received error :-
var ssNew = SpreadsheetApp.create("allowance "+(new Date));
var ss = SpreadsheetApp.openByUrl(ssNew.getUrl());
var fileId = ss.getId();
DriveApp.getFileById(fileId).addEditor("[email protected]");
Then I tried moving spreadsheet into public folder but nothing works and I receive error:-
var ssNew = SpreadsheetApp.create("allowance "+(new Date));
var folder=DriveApp.getFolderById('0AOexqtJ8UhRxPWUyk9PVxxA');
var id = ssNew.getId();
var file = DriveApp.getFileById(id);
folder.addFile(file);
Taking into account the error you're getting, here's what I think is happening:
DriveApp.getFileById
was not part of the code, so you didn't authorize the scopes required for calling this method.DriveApp.getFileById
, which requires either https://www.googleapis.com/auth/drive.readonly
or https://www.googleapis.com/auth/drive
.Review Permissions
and authorize DriveApp.getFileById
). Instead, you're probably trying to test the web app via latest code (URL ending in /dev
), which doesn't necessarily require you to update your permissions.To solve this, create a new Project version and review your permissions as you will be requested (or update any other settings for the web app, like Execute the app as, which can also prompt the authorization popup).