仅使用 javascript 将信息提交到 Google Drive 电子表格

2024-03-21

我基本上正在寻找一种仅使用 javascript 将信息提交到 Google Drive 电子表格的方法。更改特定单元格的值就是我所追求的。有人知道这是否可能吗? 谢谢。


这是在本地主机中工作的正确代码,就像在网站中一样,如果您有适当的客户端 ID 和浏览器的 API 密钥,我采用相同的 javascript 并将其放入 sencha-touch 和phoneGap 应用程序中,但它不起作用你对此有什么想法吗? :

<!DOCTYPE html>
<!--
  Copyright 2011 Google Inc. All Rights Reserved.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<html>
  <head>
    <title>JavaScript API Example</title>

    <style type="text/css">
      body { font-family: Arial; }
    </style>
    <script type="text/javascript">
      // The clientId and apiKey are available at
      // https://code.google.com/apis/console. For more information, see
      // http://code.google.com/p/google-api-javascript-client/wiki/Authentication.
      var clientId = '958693490238-nti7k45ajor0287286o8a5p4m26um32n.apps.googleusercontent.com';
      var clientSecret = 'p--MYTDoaqliiiSmP4TPFZX5';
      var apiKey = 'AIzaSyCa_oJyC4vX1KAbNoi0n0Zyqf_ZWTp8J7U';
      var scopes = 'https://www.googleapis.com/auth/fusiontables';
      var tableId;

      // Initialize the client, set onclick listeners.
      function initialize() {
        gapi.client.setApiKey(apiKey);
        document.getElementById('create-table').onclick = createTable;
        document.getElementById('insert-data').onclick = insertData;
        document.getElementById('select-data').onclick = selectData;
        window.setTimeout(function() { auth(true); }, 1);
      }

      // Run OAuth 2.0 authorization.
      function auth(immediate) {
        gapi.auth.authorize({
          client_id: clientId,
          client_secret: clientSecret,
          scope: scopes,
          immediate: immediate
        }, handleAuthResult);
      }

      // Handle the results of the OAuth 2.0 flow.
      function handleAuthResult(authResult) {
        var authorizeButton = document.getElementById('authorize-button');
        var createTableButton = document.getElementById('create-table');
        if (authResult) {
          authorizeButton.disabled = true;
          createTableButton.disabled = false;
        } else {
          authorizeButton.disabled = false;
          authorizeButton.onclick = function() { auth(false); return false; };
        }
      }

      // Run a request to create a new Fusion Table.
      function createTable() {
        var tableResource = [];
        tableResource.push('{');
        tableResource.push('"name": "People",');
        tableResource.push('"columns": [');
        tableResource.push('{ "name": "Name", "type": "STRING" },');
        tableResource.push('{ "name": "Age", "type": "NUMBER" }');
        tableResource.push('],')
        tableResource.push('"isExportable": true');
        tableResource.push('}');
        runClientRequest({
          path: '/fusiontables/v1/tables',
          body: tableResource.join(''),
          method: 'POST'
        }, function(resp) {
          var output = JSON.stringify(resp);
          document.getElementById('create-table-output').innerHTML = output;
          tableId = resp['tableId'];
          document.getElementById('table-id-1').innerHTML = tableId;
          document.getElementById('table-id-2').innerHTML = tableId;
          document.getElementById('insert-data').disabled = false;
          document.getElementById('select-data').disabled = false;
          document.getElementById('create-table').disabled = true;
        });
      }

      // Run a request to INSERT data.
      function insertData() {
        var name = document.getElementById('name').value;
        var age = document.getElementById('age').value;
        var insert = [];
        insert.push('INSERT INTO ');
        insert.push(tableId);
        insert.push(' (Name, Age) VALUES (');
        insert.push("'" + name + "', ");
        insert.push(age);
        insert.push(')');
        query(insert.join(''));
      }

      // Run a request to SELECT data.
      function selectData() {
        query('SELECT * FROM ' + tableId);
      }

      // Send an SQL query to Fusion Tables.
      function query(query) {
        var lowerCaseQuery = query.toLowerCase();
        var path = '/fusiontables/v1/query';
        var callback = function(element) {
          return function(resp) {
            var output = JSON.stringify(resp);
            document.getElementById(element).innerHTML = output;
          };
        }
        if (lowerCaseQuery.indexOf('select') != 0 &&
            lowerCaseQuery.indexOf('show') != 0 &&
            lowerCaseQuery.indexOf('describe') != 0) {

          var body = 'sql=' + encodeURIComponent(query);
          runClientRequest({
            path: path,
            body: body,
            headers: {
              'Content-Type': 'application/x-www-form-urlencoded',
              'Content-Length': body.length
            },
            method: 'POST'
          }, callback('insert-data-output'));

        } else {
          runClientRequest({
            path: path,
            params: { 'sql': query }
          }, callback('select-data-output'));
        }
      }

      // Execute the client request.
      function runClientRequest(request, callback) {
        var restRequest = gapi.client.request(request);
        restRequest.execute(callback);
      }
    </script>
    <script src="https://apis.google.com/js/client.js?onload=initialize"></script>
  </head>
  <body>
    <h1>
      Fusion Tables JavaScript Example
    </h1>
    <h2>
      (1) Authorize using OAuth 2.0
    </h2>
    <p>
      Click Authorize to start the OAuth 2.0 authorization flow. If you have
      already authorized, the button will be disabled.
    </p>
    <input type="button" id="authorize-button" value="Authorize"><br>

    <h2>
      (2) Create Table
    </h2>
    <p>
      Click "Create Table" to create an exportable Fusion Table called "People"
      with columns "Name" with type "STRING" and "Age" with type "NUMBER".
      <pre>
{
  "name": "People",
  "columns": [
    {
      "name": "Name",
      "type": "STRING"
    }, {
      "name": "Age",
      "type": "NUMBER"
    }
  ],
  "isExportable": true
}</pre>
    </p>
    <input type="button" id="create-table" value="Create Table"
        disabled="disabled">
    <p id="create-table-output"><i>table response goes here...</i></p><br>

    <h2>
      (3) Insert data
    </h2>
    <p>
      Insert data into the newly created table.
    </p>
    <pre>INSERT INTO <span id="table-id-1">[table_id]</span> (Name, Age) VALUES ([name], [age])</pre>
    <label>Name:</label>
    <input type="text" id="name"><br>
    <label>Age:</label>
    <input type="age" id="age"><br>
    <input type="button" id="insert-data" value="Insert data"
        disabled="disabled">
    <p id="insert-data-output"><i>insert response goes here...</i></p><br>

    <h2>
      (4) Select all the rows from the table
    </h2>
    <p>
      Select the data that has been inserted into the newly created table.
    </p>
    <pre>SELECT * FROM <span id="table-id-2">[table_id]</span></pre>
    <input type="button" id="select-data" value="Select data"
        disabled="disabled">
    <p id="select-data-output"><i>select response goes here...</i></p>
  </body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

仅使用 javascript 将信息提交到 Google Drive 电子表格 的相关文章

  • CSS 文本装饰:反向

    我很惊讶 CSS 中没有 text decoration reverse 因为使用 JavaScript 来实现似乎非常尴尬 IE 将元素的前景色和背景色分别设置为父元素的背景色和前景色 我注意到了 JavaScript 技术here ht
  • readFile() 和 readFileSync() 之间的区别

    以下代码将index html 的内容 仅包含文本hello world 输出到浏览器 然而 当我更换readFile with readFileSync 请求超时 我缺少什么 是否需要不同类型的缓冲区 我使用的是node 0 61 和ex
  • React-Native 博览会 POST Blob

    我正在使用 React Native 和 expo 并尝试通过 fetch api 发布 blob 图像 我对正文使用表单数据格式 并且我有下一个代码 const blob await response blob const form ne
  • 处理量角器中的未知错误

    我有一个protractor通过配置多个浏览器进行设置multiCapabilities 在 browserstack 上运行测试 我的主要量角器规格 测试之一包含以下内容afterEach block afterEach function
  • 在 IOS9 中的 Cordova 应用程序上使用 JQuery/Javascript 的 window.history 问题

    我在 IOS9 测试版 下使用 Cordova 应用程序时遇到问题 我正在使用最新的 Cordova 和 JQuery 移动版本 window history 未更新 导致以下故障 window history go 1 无法返回页面 即使
  • 现在 JavaScript 的无限循环会导致浏览器崩溃吗?

    我正在学习 JavaScript 对编程很陌生 碰巧遇到了这些无限循环 据说这些循环会永远持续下去并使浏览器崩溃 但是当我用这些代码创建一个循环时 i 0 while i lt 10 document write i 浏览器只是继续加载它
  • 如何字符串化整个 Javascript 对象(包括 __proto__ 属性)?

    如果这是重复的 我很抱歉 到目前为止我找不到相同的问题 我的对象中有一个具有各种方法的对象 proto 成员 我们称这个对象的类型为myObjectType 稍后我必须做一个JSON stringify myObjectType 问题是 当
  • Dojo DataGrid (DGrid) 添加复选框列

    我在用DojoDgrid 但是我正在尝试添加一个复选框列 但我不确定该方法 我一直在看的大多数教程都遵循不同的代码结构 我无法创建复选框列 我想创建一个复选框列来选择行 Code 这里还有一个Fiddle http jsfiddle net
  • 创建地图后向 Google 地图 v3 添加标记

    我对使用 Google Maps API 比较陌生 现在我正在开发一个项目 用户可以选择各种搜索过滤器并查看结果自动显示在地图上 而无需重新加载页面 到目前为止 我的方法是创建一个控制地图的 Javascript 对象 以便我可以按照我的意
  • 如何在 jQuery/javascript 中获取边框宽度

    如何解析边框宽度 style border solid 1px black 在 jQuery javascript 中 elem css border width 不这样做 注意我需要解析 css 的宽度 因为元素可能是display no
  • svg 圆不是用 javascript 绘制的

    我一直在尝试使用 HTML 中的 javascript 来进行 svg 操作的 hello world 我编写了下面的代码 虽然它生成了正确的 html 但我在浏览器中没有看到任何输出 也没有看到任何错误
  • Firefox:按下鼠标按钮时鼠标悬停不起作用

    这是我想做的 https gfycat com ValidEmbarrassedHochstettersfrog https gfycat com ValidEmbarrassedHochstettersfrog 我想强调一些 td 对象在
  • 更改 jQuery 中链接的标题

    我有一个 id 为 helpTopicAnchorId 的链接 我想在 jQuery 中更改其文本 我该怎么做呢 helpTopicAnchorId text newText P S the jQuery 文档 http docs jque
  • 现已弃用使用 Google Places API 获取多种类型

    谷歌最近宣布 自 2016 年 2 月 16 日起 types 参数已被弃用 取而代之的是新的类型参数 每个搜索请求仅支持一种类型 我的问题是 现在有什么方法 不使用已弃用的参数 从单个 API 调用中获取多个地点类型吗 谢谢 None
  • datatables.search 函数修改后的奇怪行为

    这个问题是后续问题这个问题 https stackoverflow com questions 54671211 overriding datatables js search behavior 我已经创建了这个 JSFiddle http
  • 通过 javascript 将 onsubmit 添加到表单

    您将如何仅通过 Javascript 将 OnSubmit 属性插入到表单中 我对 javascript 还很陌生 所以如果您能够提供详细的示例代码 那将是最有帮助的 情况是这样的 我通过 Chargify 支付平台 使用托管注册页面来处理
  • 来自 geoJSON 的 Google 地图航点

    我想从 geoJSON 文件加载行程 目前来说 它是有效的 但只有两点 但我需要添加 4 或 5 个航路点 我的代码只读取前两个点并将它们设置为起点和目的地 这是我的代码 google maps event addListener map
  • 用圆形雷达数学方法表示点

    我正在编写一个简单的应用程序 它可以向您显示您周围的朋友 但不是在法线地图中 而是在像 UI 这样的真正圆形雷达上 https i stack imgur com Au3IP png https i stack imgur com Au3I
  • 如何在 JavaScript 中将样式属性重置为其 CSS 默认值?

    在 php 生成的页面上有几个这样的元素 td class defaultTDStyle style color userDefinedCustomColor td 因此有一个默认样式 我应用了几个额外的样式来覆盖 CSS 中定义的样式 有
  • 将变量从 PHP 传递到 JavaScript 的有效方法[重复]

    这个问题在这里已经有答案了 有时我必须将一些变量从 PHP 传递到 JS 脚本 现在我是这样做的 var js variable 但这非常丑陋 我无法在 js 文件中隐藏我的 JS 脚本 因为它必须由 PHP 解析 处理这个问题的最佳解决方

随机推荐

  • SDL2 升起窗口而不给予焦点

    我需要在窗口上显示工具提示 我正在使用工具提示创建第二个窗口 并使用 SDL RaiseWindow 将其带到顶部 然而 这样做会导致工具提示窃取焦点 这不是我想要的 有没有办法在不改变焦点的情况下将窗口置于顶部 另外 有没有办法在不改变窗
  • inDither = true Android

    有人可以解释一下设置时到底发生了什么吗抖动 true在 Android 中配置位图的上下文中 在 Developer Android 上可以阅读有关静态变量的信息 Config RGB 565 根据源的配置 此配置可能会产生轻微的视觉伪影
  • 为什么Java的SimpleDateFormat不是线程安全的? [复制]

    这个问题在这里已经有答案了 请用代码示例说明为什么 SimpleDateFormat 不是线程安全的 这堂课有什么问题 是SimpleDateFormat的格式化函数的问题 请给出在课堂上演示此错误的代码 FastDateFormat 是线
  • 如何在PyUsb中绑定/取消绑定USB设备?

    我需要在 python 脚本上打开 关闭多个 USB 设备 我可以使用 PyUsb 绑定和取消绑定 USB 设备吗 我可以使用 shell 命令来做到这一点 关闭电源 echo device nuber gt sys bus usb dri
  • SQLite - 表约束唯一和列约束唯一之间有什么区别?

    关于 SQLite 的问题 在 CREATE TABLE SQL 中 我们可以通过以下任一方式添加 UNIQUE 约束 列约束或表约束 我的问题很简单 他们的工作方式不同吗 我能发现的唯一区别是 在表约束中 可能有多个indexed col
  • 找出 MySQL 在 Mac OS X 上的安装位置

    如何找出 Mac OS X 10 7 9 上 MySQL 的安装位置 我安装了 MAMP 所以我认为它与此安装捆绑在一起 要检查 MAMP 的 MySQL 版本 请在终端中使用以下命令 Applications MAMP Library b
  • DOCX w:t(文本)元素跨越多个 w:r(运行)元素?

    我们编写了一个软件 可以从 Word 文档的内部 XML 文件中处理 XML 并用替换值替换某些代码 有时我们发现此类代码在多次运行之间被破坏 以下是我们有时会遇到的此类情况的示例
  • 为子类添加额外的“方法”

    这是一个概念性问题 旨在了解如何在 C 中完成 OOP 技术 我知道它不实用或不推荐 并且有许多语言可以更好地实现此目的 但我只是看看作为初学者如何完成它到 C 假设我有一个名为的基础对象Thing 它将有一些数据和一些功能 然后我想添加另
  • 出现 TypeError:this.props 在 ReactJs 上未定义

    我正在尝试做教程 https facebook github io react docs tutorial html https facebook github io react docs tutorial html import Reac
  • 带有“fromCharCode”(字符长度)的 Javascript 映射数组

    以下内容来自 Chrome 控制台中的交互式会话 myarray gt 67 65 84 String fromCharCode 67 gt C String fromCharCode 67 length gt 1 String fromC
  • 可利用的 C# 函数 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 这个问题类似于可利用的 PHP 函数 https stackoverflow com questions 3115559 exploi
  • Kendo UI 绑定弹出编辑器中的下拉值

    我有一个 Kendo 网格 它可以选择使用弹出编辑器添加新记录 弹出编辑器中的一个字段是 DropDownList 当我打开弹出编辑器时 我从下拉列表中预先选择了第一条记录 由于我预先选择了它 我希望它在网格内自动创建 绑定 当按 更新 时
  • Python 会缓存重复访问的文件吗?

    我想知道 Python 是否足够聪明 可以缓存重复访问的文件 例如当使用 pandas 读取相同的 CSV 或多次 unpickle 相同的文件时 这是否是 Python 的责任 还是应该由操作系统来处理 不 Python 只是一种语言 它
  • Snakemake - 如何使用文件的每一行作为输入?

    我需要使用文件的每一行tissuesused txt作为snakemake中并行规则的输入 我想总共大约有 48 个工作机会 for line in cat tissuesused txt do echo Sorting line phen
  • 如何与具有哈希属性的 Perl 对象交互?

    我有一个包含多个变量的类 其中一个是散列 runs sub new my class name my self name gt name runs gt times gt bless self class return self 现在 我要
  • 无法访问VueJS中的根数据

    这是我在 stackoverflow 上的第一篇文章 如果我做错了什么 请提前抱歉 我的问题 我已经设置了一个 VueJS 项目 并且正在尝试从另一个组件获取放入 App vue 中的数据 为此 我使用 this root count 为例
  • 带条件的 LINQ to SQL 急切加载

    我正在尝试学习 LINQ to SQL 并且发现了 LoadWith 函数 我找到的所有示例都会加载您在 LoadWith 函数中指定的表中的所有记录 例如 var dlo new DataLoadOptions dlo LoadWith
  • 在 IMAP 收件箱中搜索来自特定发件人的邮件并使用通配符?

    是否可以使用通配符在 IMAP 文件夹中搜索特定发件人 typ data M SEARCH None from security website IMAP RFC 3501 6 4 4 https www rfc editor org rf
  • 如何在 C# 6.0 中实现 INotifyPropertyChanged?

    答案是这个问题 https stackoverflow com questions 1315621 implementing inotifypropertychanged does a better way exist 1316417 13
  • 仅使用 javascript 将信息提交到 Google Drive 电子表格

    我基本上正在寻找一种仅使用 javascript 将信息提交到 Google Drive 电子表格的方法 更改特定单元格的值就是我所追求的 有人知道这是否可能吗 谢谢 这是在本地主机中工作的正确代码 就像在网站中一样 如果您有适当的客户端