I have a speadsheet extension, which saves many docs metadata.
It uses an add-on menu to activate a merge files function, which uses DocumentApp.openBy..()
My question is a little like this.
I modified the manifest (appsscript.json) to have the following permissions:
- https://www.googleapis.com/auth/documents
- https://www.googleapis.com/auth/drive
- https://www.googleapis.com/auth/spreadsheets
It still does not work.
Here's my code.
makeMerge
is triggered by an add-on menu button.
function onOpen(e) {
var ui = SpreadsheetApp.getUi();
ui.createAddonMenu().
addItem("merge", 'uiTrigger').
addToUi();
}
function uiTrigger() {
makeMerge(SpreadsheetApp.getActiveSheet(), DriveApp.getRootFolder());
}
function makeMerge(sheet, folder) {
if (folder === null || folder === undefined) {
folder = DriveApp.getRootFolder();
}
var dataRows = sheet.getDataRange().getValues().length - 1;
var names = sheet.getRange(2, 1, dataRows, 1).getValues();
var docsRef = sheet.getRange(2, 8, dataRows, 1).getValues();
var toDownload = sheet.getRange(2, 11, dataRows, 1).getValues();
for (var i in toDownload) {
var name = names[i][0];
var docRef = docsRef[i][0];
Logger.log(docRef);
try {
var doc = DocumentApp.openByUrl(docRef);
} catch(error) {
Logger.log(error);
}
}
}
I have no idea (I don't use spreadsheet custom function) why do I have the same issue? How do I give my script permission to open Documents?
catch()
block : Exception: Document is missing (perhaps it was deleted, or you don't have read access?) and have an undefineddoc
variable. 2. Yes. I run other functions. And I do have permission to access my spreadsheet. 3. All granted scopes are listed in manifest. (appsscript.json) and all files are own by myself. – 程柏硯https://docs.google.com/a/XXXX/open?id=longFileIDString
2. I did grant the document scope, and these documents are owned by myself. 3. Run any function in script triggers oauth prompt 4. It does not work. This script is a standalone, sogetActivesheet()
can only run in extenstion sandbox. Therefore, it runs good until accessing google docs. – 程柏硯