gpt4 book ai didi

java - 无法在 Nest Rest API 上设置温度

转载 作者:行者123 更新时间:2023-11-30 06:47:31 26 4
gpt4 key购买 nike

我的开发者权限设置为:

  • 离开 - 读/写 v2
  • 能源 - 阅读 v2
  • 预计到达时间 - 阅读 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 等,这都是一致的。我已经尝试过以下每种格式的请求(除此之外,以下是在文档和此处找到的各种示例)

# 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"}

最佳答案

@urman 善意地发现,我在设置请求中的“thermostats”中缺少一个 's'。言语无法表达这种尴尬:)

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

关于java - 无法在 Nest Rest API 上设置温度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43436183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com