I am using the Google Sheets API to create a spreadsheet. I want to add an onEdit
function to this sheet that calls out and does an ajax request.
- Using either the app script api or the spreadsheet API I want to create the
onEdit
function, something like:
// Following comment ensures UrlFetchApp authorization will be prompted:
// UrlFetchApp.fetch()
function onEdit(e) {
var range = e.range
var currentSheet = range.getSheet()
var sheetId = currentSheet.getParent().getId();
var url = 'https://example.com/synchronise?sheetId=' + sheetId;
var response = JSON.parse(UrlFetchApp.fetch(url).getContentText());
}
and I want to attach that to the sheet I am creating with the API. My app uses Google OAuth so I am hoping I can also deal with the permissions required to make external calls as part of the OAuth authentication process (but happy if when the user opens the sheet it asks them then which I suspect might be the case?)
So my question is what is the appraoch to
a) create a script and attach it to a sheet
b) programmatically (or via API) get the user to accept permissions for the script to call out?
What I want to replicate is going to a sheet, clicking tools->script editor and pasting in the function but do that with an API
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…