如何使用 LUA 发送带 API key 的 GET 请求

我正在尝试从 Google Sheet API 获取请求,但是我不知道如何在代码中传递 API key。

local http = require("socket.http")
local body, code, headers, status = http.request("https://sheets.googleapis.com/v4/spreadsheets/1AQK1WHGsavVmhNugAipMsrweB3m25xp01vtzGA8BvwE/values/Global!A1:D5")
print(code, status, body)

现在我收到了403错误。

点赞
用户11352221
用户11352221

将其作为查询参数添加到 URL 的末尾,像这样:

http.request("https://sheets.googleapis.com/v4/spreadsheets/[spreadsheet-id]/values/Global!A1:D5?key=[YOUR_API_KEY]")

下次,您可以通过单击 "尝试此 API " 窗口中的展开图标,检查 Sheets API 如何发出请求。

[1] https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/get

2019-12-31 09:52:11