【问题标题】:Is it possible to post/append to a google spreadsheet with just an api key?是否可以仅使用 api 密钥发布/附加到谷歌电子表格?
【发布时间】:2018-07-19 13:10:39
【问题描述】:

我一直在广泛阅读有关表格 v4 的文档。我正在尝试仅使用 apikey(不使用 oauth)将表单数据发布到谷歌电子表格。我不希望客户/用户必须登录才能填写我的表单。

The docs indeed 仅表示 oauth。有没有办法解决这个问题?无论如何将简单表单​​的数据发送到谷歌表格?

这是我正在尝试的代码。

const postURL = `https://sheets.googleapis.com/v4/spreadsheets/1GOSI8dDYmuBIznSV-Ge9WtY_RSivo6rEpnpC8EZDnuw/values/orders!:append?insertDataOption=INSERT_ROWS&valueInputOption=RAW&key=mykey`;

   let opts = {
      method: 'POST',
      body: JSON.stringify({
        // "range": 'orders',
        "majorDimension": 'ROWS',
        "values": [
          this.state.email
        ],
      })
    }


      e.preventDefault()
        fetch(postURL, opts)
          .then(response => console.log('Success!', response))
          .catch(error => console.error('Error!', error.message))


  }

【问题讨论】:

  • 您当然可以编写一个 Apps Script webapp,它接受表单输入,然后将其写入 Google 表格文件。您将部署 webapp 以像您一样执行。如果没有像 webapp 这样的 oauth 授权中介,就无法以编程方式写入 Google 表格。
  • 很遗憾,您不能使用 API 密钥使用 POST 和 PUT。另一方面,API 密钥可以使用 GET 方法。人们认为这是出于安全考虑。因此,您可以使用 tehhowch 的建议和/或 the service account 来实现它。

标签: google-sheets google-sheets-api


【解决方案1】:

作为评论者,你不能。您只能使用 api 密钥获取。该死!

但是,这里有一个关于如何在电子表格端使用脚本提交表单的非常好的指南:

https://github.com/jamiewilson/form-to-google-sheets

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多