Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Extension Writing to Google Spreadsheet [closed]

I've been doing some research and for some reason can't find a good example showing this anywhere, and I am starting to wonder if it's even possible.

What's I'm looking to do is to have my extension write data within a Google Spreadsheet, so that the sheet is being used as a database.

Does anyone have any documentation that I could follow through? Considering that the Spreadsheet API doesn't seem to allow JavaScript, is that even possible?

THanks.

like image 362
Albert Avatar asked Dec 08 '13 06:12

Albert


People also ask

Why can't I type in Google Sheets?

Make sure you're using a browser that works with Google Drive and Docs, Sheets, and Slides. Make sure your file isn't too large to be edited. Clear your cache and cookies. Turn off browser plugins or extensions in Chrome, Firefox, Internet Explorer, or Safari.

Why is Google Sheets not working in Chrome?

Clear your cache and cookies Apart from your extensions, your browser cache and cookies may also cause various Google Sheets glitches. That's why clearing your cache and cookies is what you should do next. If you're on Chrome or other Chromium-based browsers, click on the menu icon and History.


1 Answers

Yes, it is definitely possible. I have used the Spreadsheet API extensively using Javascript. You'll need to use the Protocol version of the API as documented here: https://developers.google.com/google-apps/spreadsheets/

This requires sending signed requests using OAuth2 (the older auth protocols aren't really reliable anymore.) so I suggest using an OAuth2 library like JSO. https://github.com/andreassolberg/jso

When writing your javascript you'll need to write functions that create an XML string to interface with the Protocol API. Parsing the responses is pretty straight forward. I've included a snippet of the code I've used. You can also see my answer to a related question using JQuery here. JQuery .ajax POST to Spreadsheets API?

function appendSpreadsheet(){   //Constructs the XML string to interface with the Spreadsheet API.  //This function adds the value of the param foo to the cell in the first empty row in the column called 'columnTitle'.   //The Spreadsheet API will return an error if there isn't a column with that title.  function constructAtomXML(foo){   var atom = ["<?xml version='1.0' encoding='UTF-8'?>",           '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">',//'--END_OF_PART\r\n',           '<gsx:columnTitle>',foo,'</gsx:columnTitle>',//'--END_OF_PART\r\n',           '</entry>'].join('');   return atom;  };   var params = {  'method': 'POST',  'headers': {    'GData-Version': '3.0',    'Content-Type': 'application/atom+xml'  },  'body': constructAtomXML(foo)  };   var docId //Get this from the spreadsheet URL or from the Google Drive API.  var worksheetId = 'od6'; //The worksheet Id for the first sheet is 'od6' by default.   url = 'https://spreadsheets.google.com/feeds/list/'+docId+'/'+worksheetId+'/private/full';   sendSignedRequest(url, handleSuccess, params); //Use your OAuth2 lib } 
like image 56
Ohhh Avatar answered Sep 25 '22 13:09

Ohhh