Chrome扩展程序写入Google电子表格 [英] Chrome Extension Writing to Google Spreadsheet

查看:101
本文介绍了Chrome扩展程序写入Google电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些研究,出于某种原因无法找到一个很好的例子显示这一点,我开始怀疑它是否有可能。

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.

我想要做的是让我的扩展程序在Google Spreadsheet中写入数据,以便将表单用作数据库。

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.

有没有人有我可以遵循的文档?考虑到Spreadsheet API似乎不支持JavaScript,甚至有可能吗?

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。

推荐答案

是的,这绝对有可能。我已经广泛使用Javascript使用Spreadsheet API。您需要使用以下协议版本的API: https://开发人员.google.com / google-apps / spreadsheets /

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/

这需要使用OAuth2发送签名请求(旧的认证协议不再可靠)。所以我建议使用类似JSO的OAuth2库。
https://github.com/andreassolberg/jso

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

在编写JavaScript时,您需要编写函数来创建XML字符串以与Protocol API进行交互。解析响应非常简单。我已经包含了我用过的代码片段。你也可以在这里看到我使用JQuery的相关问题的答案。 JQuery .ajax发布到Spreadsheets API

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
}

这篇关于Chrome扩展程序写入Google电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆