Insert new rows into Google Spreadsheet via cURL/PHP - HOW? -


is there script or tutorial on how this? how implement inserting of data php application google spreadsheet?

i've looked @ api (https://developers.google.com/google-apps/spreadsheets/) , there no php codes/examples.

i've tried zend library implementation, seems outdated approach getting silly errors on simple row insert.

i don't think can use google apps script (https://developers.google.com/apps-script/reference/spreadsheet/) don't see how can code , trigger php script.

anything else?

isn't there workable api can use , tap into?

i don't think can use google apps script don't see how can code , trigger php script

sure can. can create web service using google apps script, can receive , process service requests. it's simple pass parameters web service, done using curl, instance.

the following example simple spreadsheet 2 columns. can add further rows by:

curl -l <script url>?col1='value column 1'&col2='another value' 

or browser url:

https://<script url>?col1='value column 1'&col2='another value' 

this example spreadsheet published here, , below example url can used add row:

https://script.google.com/macros/s/akfycbzvdfmoeaqc4mdzhwcnwf0cunx64ynhhnkiltyhqtpbrainuf9e/exec?col1='value column 1'&col2='another value' 

instructions

here step-by-step.

  1. open google spreadsheet, ensure spreadsheet accessible (public)
  2. tools --> script editor
  3. copy code below , paste editor
  4. replace --spreadsheet-id-- sheet's id (easy find this)
  5. file --> save
  6. publish --> deploy web-app --> version = new ; set access needed
  7. authorize (will prompt creds) --> deploy
  8. you url script
  9. append ?col1='colum1data'&col2='colum2data' url or edit needed push data spreadsheet url
  10. done

(thanks vr00n.)

code.gs

this stand-alone or container-bound script; either way, need supply id of spreadsheet, since web app not run within spreadsheet context. rather display html, uses contentservice serve simple text - can elaborate in way appropriate application.

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 = '--spreadsheet-id--'; // spreadsheet id     var sheet = spreadsheetapp.openbyid(id).getactivesheet();     var newrow = sheet.getlastrow() + 1;     var rowdata = [];     (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[0] = value;           break;         case 'col2':           rowdata[1] = 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, ""); } 

you should read on google's content service documentation, cautions around redirection, , sensitive information.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -