asp.net - How to send List of objects to google execution api and handle it in google apps script -
in general want export data asp.net mvc application google sheets example list of people. i've set connection , authenticated app google account (trough oauth2) i'm trying send list of objects api , handle in script (by putting data in new file) , couldn't head around this.
here sample code in app sends request.
public async task<actionresult> sendtestdata() { var result = new authorizationcodemvcapp(this, new appflowmetadata()). authorizeasync(cancellationtoken.none).result; if (result.credential != null) { string scriptid = "my_script_id"; var service = new scriptservice(new baseclientservice.initializer { httpclientinitializer = result.credential, applicationname = "test" }); ilist<object> parameters = new list<object>(); var people= new list<person>(); // next i'm selecting data db.person variable parameters.add(people); executionrequest req = new executionrequest(); req.function = "testfunction"; req.parameters = parameters; scriptsresource.runrequest runreq = service.scripts.run(req, scriptid); try { operation op = runreq.execute(); if (op.error != null) { // api executed, script returned error. // extract first (and only) set of error details // idictionary. values of dictionary // script's 'errormessage' , 'errortype', , // array of stack trace elements. casting array // json jarray allows trace elements accessed // directly. idictionary<string, object> error = op.error.details[0]; if (error["scriptstacktraceelements"] != null) { // there may not stacktrace if script didn't // start executing. newtonsoft.json.linq.jarray st = (newtonsoft.json.linq.jarray)error["scriptstacktraceelements"]; } } else { // result provided api needs cast // correct type, based upon types apps // script function returns. here, function returns // apps script object string keys , values. // convenient cast return value json // jobject (folderset). newtonsoft.json.linq.jobject folderset = (newtonsoft.json.linq.jobject)op.response["result"]; } } catch (google.googleapiexception e) { // api encountered problem before script // started executing. addalert(severity.error, e.message); } return redirecttoaction("index", "controller"); } else { return new redirectresult(result.redirecturi); } }
the next how handle data in scripts - serialized json there?
the execution api calls rest calls payload should serialized per that. stringified json typically fine. gas function should parse payload consume encoded lists
var data = json.parse(payload);
Comments
Post a Comment