【问题标题】:Unable to set temperature on Nest rest API无法在 Nest Rest API 上设置温度
【发布时间】: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”,现在正在处理“未找到”错误。如果我仍然被困在一个星期......谢谢你!
  • 知道了。终于工作了

标签: java python curl nest-api


【解决方案1】:

正如@urman 所见,我在设置请求的“恒温器s”中缺少一个“s”。言语无法表达尴尬:)

作为所有 Nest 开发人员阅读的请求 - 是否可以返回不同的错误消息?即使是 404 也会指向 url 与“内容”中更明显的错误。

【讨论】:

  • 没问题!它发生在我们所有人身上。您是对的,但是 API 应该返回 404,这更有意义。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-27
  • 2014-08-19
  • 2016-07-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多