我正在研究 chatbot project . 我希望用户能够将列表项输入到Google表格中 . 聊天机器人在DialogFlow上,我创建了意图,并切换了webhook . 我现在处于Google Cloud 端功能中,并在Google工作表上创建了一个新功能.760942_ . 我已经__60943_从要在chatbot中显示给用户的工作表中的项目列表 .

我是nodejs的新手并且当然对Oauth不太了解,但是我将我的工作表设置为可以被互联网上的任何人编辑,我也有一个工作的API密钥 . 为了尝试深入了解基础知识,我继续https://apitester.com来测试那里的HTTP请求 . I can GET a response easily that returns the list of items I already have. However, my POST response is still returning issues, although the site did indicate that the request "PASS"ed.

我的POST请求

https://sheets.google.com/v4/spreadsheet/<SPREADSHEETID>/values/A1:append?includeValuesInResponse=true&key=<MY_API_KEY>

<SPREADSHEETID><MY_API_KEY> 匹配我的凭据 .

我的要求机构:

{
  "values": [ ["Hello", "World"] ],
  "range": "Sheet1!A1:B1",
  "majorDimension": "ROWS"
}

响应:

HTTP/1.1 301 Moved Permanently
Location: https://docs.google.com/spreadsheets?usp=direct_url
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Date: Thu, 18 Oct 2018 07:31:14 GMT
Expires: Sat, 17 Nov 2018 07:31:14 GMT
Cache-Control: public, max-age=2592000
Server: sffe
Content-Length: 248
X-XSS-Protection: 1; mode=block
Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35"

我查了 301 error code ,发现它是一个重定向消息,表示服务器端错误 . 我读到它应该是自我修复的,因为您的请求将被重定向到上面 Location 值中的相应站点 . 但我也复制了 Location 链接,发现它只是把我带到我的个人Google Cloud 端硬盘 . 我在其他地方读到这可能是因为Google正在通过安全链接进行通信 . 我查看了我的Google表格以防万一,但没有任何改变 .

Anyway, is it possible to test the append request before I code it into my Google Cloud Function? If so, where can I test and how can I make sure that the request goes through (with hopefully just an API key and no Oauth creds)?

我尝试在文档页面(https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/append)(右侧的"Try This API")上执行此操作,但我只是得到一个永无止境的红色进度圈 .

请帮忙!如果唯一的答案是Oauth,请帮助我过去指导Oauth文档,因为我没有发现它非常有帮助 .

Thank you!

EDIT 1 好的,我一直在尝试一些事情 . Oauth游乐场不适合我,但是这个网站(https://developers.google.com/apis-explorer/#p/sheets/v4/sheets.spreadsheets.values.append)允许我在我的电子表格中发布一个新行 . (我不得不将授权OAuth 2.0切换为ON . )

所以现在我有Oauth工作,如何使用node.js将其转换为我的Google Cloud Function?我是否将我的Oauth令牌保存到某些变量,然后将它们添加到 Headers 中?