【发布时间】:2017-04-16 10:24:53
【问题描述】:
我的开发者权限设置为:
- 离开 - 读/写 v2
- 能源 - 阅读 v2
- ETA - 阅读 v1
- 邮政编码 - 阅读 v2
- 结构 - 读/写 v1
- 温控器读/写 v6
我可以很容易地得到温度:
$ curl -s -L -X GET "https://developer-api.nest.com/devices/thermostats/ADK.....-/target_temperature_c" -H "Content-Type: application/json" -H "Authorization: Bearer c.IQvC....."
$ 11.0
但是,在尝试设置温度时,我一直收到“发送的内容无效”响应。无论我使用 Curl、Java、python 等,这都是一致的。我尝试过以下每种格式的请求(除此之外,以下是文档中和 SO 上的各种示例)
# With Auth Token in URL
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/target_temperature_c?auth=c.IQvCNgfU......" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "10"
# Without write target in URL
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "{\"target_temperature_c\":10}"
# Without write target in URL, not escaping quotes
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d '{"target_temperature_c":10}'
# With write target in URL
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/target_temperature_c" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "10"
# Try and set a String field instead
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/label" -H "Authorization: Bearer c.IQvCNgfU......" -H "Content-Type: application/json" -d "A Label"
# Try it without Json as a content type
curl -s -L -X PUT "https://developer-api.nest.com/devices/thermostat/ADK.....-/label" -H "Authorization: Bearer c.IQvCNgfU......" -d "A Label"
这是完整的错误响应:
{"error":"Invalid content sent","type":"https://developer.nest.com/documentation/cloud/error-messages#invalid-content-sent","message":"Invalid content sent","instance":"91c86174-576d-43b7-a586-fcc07a92efa5"}
【问题讨论】:
-
当您尝试使用华氏值设置华氏存储桶时会发生什么?
-
同样的反应。我还尝试设置“标签”以查看是否是数字格式问题。请参阅“尝试设置字符串字段”
-
您在恒温器中缺少一个“s”。应该是https://developer-api.nest.com/devices/thermostats/ADK...等等等
-
JTFC ............我花了好几个小时摆弄该死的身份验证和格式化。我添加了“s”,现在正在处理“未找到”错误。如果我仍然被困在一个星期......谢谢你!
-
知道了。终于工作了