【发布时间】:2021-01-18 00:05:19
【问题描述】:
我正在使用“Lua”编程语言在 Home Center 3(来自 Fibaro)中构建一个所谓的“Quickapp”。我想从 Tado api 获取一些数据,但它的记录很差。我不断从控制台收到以下消息:
未经授权访问此资源需要完全身份验证
我认为那是因为我需要从请求中分配 Bearer 令牌,但我有点不知所措......
这是我目前所拥有的:
function QuickApp:fetchTadoData(username,password,client_secret)
local url = "https://auth.tado.com/oauth/token"
local postdata = {
["client_id"] = "tado-web-app",
["grant_type"] = "password",
["scope"] = "home.user",
["username"] = username,
["password"] = password,
["client_secret"] = client_secret
}
local extraheaders = {
["content-type"] = "application/json"
}
self.http:request(url, {
options={
headers = extraheaders,
data = json.encode(postdata),
method = "POST"
},
success = function(status)
self:debug(status.data)
end,
error = function(error)
errorlog("Error getting data: "..error)
self:debug("hallo")
end
})
end
我知道获取“不记名令牌”响应的 Curl 代码:
curl -s "https://auth.tado.com/oauth/token" -d client_id=tado-web-app -d grant_type=password -d scope=home.user -d username="you@example.com" -d password="Password123" -d client_secret=wZa
但我不知道如何将其翻译成上面的 Lua 代码。任何帮助表示赞赏!
【问题讨论】: