c - How to post to Google Docs Form directly -
i'm working on project need post data acquire google form , obtain data spreadsheet. cannot use google apps script , need method using direct post method doing function gsm module. solutions posted take consideration old structure of google form provides form key.like solution described in one:
http://www.open-electronics.org/how-send-data-from-arduino-to-google-docs-spreadsheet/
the link current form this.
https://docs.google.com/forms/d/14mkyg3fpnezzuc_nxuswhlz5jhplvjywtaeob7f_w7g/viewform
any appreciated.
is requirement google form in middle of this? if enough able post data spreadsheet, here's google-apps-script 1 side of problem: simple web service accept form data query string, , write spreadsheet.
this examples assumes simple spreadsheet, 3 columns, "timestamp", "col1" , "col2". edit code suit situation.
you can see spreadsheet here, , make test post.
/** * doget() function add data spreadsheet. * * spreadsheet data provided querystring, e.g. ?col1=1&col2='pizza' * * from: http://stackoverflow.com/a/18725479/1677912 * * @param {event} e event passed doget, querystring * @returns {string/html} html served * * test urls (adjust id needed): * https://script.google.com/macros/s/--dev-script-id--/dev?col1=1&col2='pizza' * https://script.google.com/macros/s/--pub-script-id--/exec?col1=1&col2='pizza' */ function doget(e) { logger.log( json.stringify(e) ); // view parameters var result = 'ok'; // assume success if (e.parameter == undefined) { result = 'no parameters'; } else { var id = '--sheet-id---'; // spreadsheet id responses var sheet = spreadsheetapp.openbyid(id).getactivesheet(); var newrow = sheet.getlastrow() + 1; var rowdata = []; rowdata[0] = new date(); // timestamp (var param in e.parameter) { logger.log('in loop, param='+param); var value = stripquotes(e.parameter[param]); //logger.log(param + ':' + e.parameter[param]); switch (param) { case 'col1': rowdata[1] = value; break; case 'col2': rowdata[2] = value; break; default: result = "unsupported parameter"; } } logger.log(json.stringify(rowdata)); // write new row spreadsheet var newrange = sheet.getrange(newrow, 1, 1, rowdata.length); newrange.setvalues([rowdata]); } // return result of operation return contentservice.createtextoutput(result); } /** * remove leading , trailing single or double quotes */ function stripquotes( value ) { return value.replace(/^["']|['"]$/g, ""); }
Comments
Post a Comment