首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Ecobee:只返回部分结果的响应

Ecobee:只返回部分结果的响应
EN

Stack Overflow用户
提问于 2016-05-28 17:18:21
回答 1查看 194关注 0票数 0

使用Google脚本尝试使用生态蜜蜂API与我的恒温器对话。在下面的代码中,json的值是"{ "status": { "code": 0, "message": "" } }"。有关正确的完整响应,请参阅问题后面的curl结果。

出于某种原因,response只是从服务器返回的三个结果(pagethermostatListstatus)中获取最终元素(status)。

我遗漏了什么?

Google脚本如下:

代码语言:javascript
运行
复制
function getSettings() {
  var response = fetchSettings();
  var json = response.getContentText();
  var data = JSON.parse(json);
  // response, json, and data only show `status` result
}

function fetchSettings() {
  try {
    var headers = {
      'Authorization': 'Bearer AUTH_TOKEN'
    };
    var payload = { 
      'selection' : { 
        'selectionType':'registered',
        'selectionMatch': '',
        'includeRuntime': 'true'
      } 
    };

    var options = {
      'method': 'get',
      'headers': headers,
      'contentType': 'text/json',
      'payload': JSON.stringify(payload);
    };
    var URL = 'https://api.ecobee.com/1/thermostat?format=json'
    return UrlFetchApp.fetch(URL,options);
  } catch(e) {
    return e;
  }
}

使用curl的步骤如下:

代码语言:javascript
运行
复制
curl -s -H 'Content-Type: text/json' -H 'Authorization: Bearer AUTH_TOKEN' 'https://api.ecobee.com/1/thermostat?format=json&body=\{"selection":\{"selectionType":"registered","selectionMatch":"",includeRuntime":true\}\}'

我得到了充分的结果。

代码语言:javascript
运行
复制
{
  "page": {
    "page": 1,
    "totalPages": 1,
    "pageSize": 2,
    "total": 2
  },
  "thermostatList": [
    {
      "identifier": "12345",
      "name": "Downstairs",
      "thermostatRev": "160528163253",
      "isRegistered": true,
      "modelNumber": "athenaSmart",
      "brand": "ecobee",
      "features": "",
      "lastModified": "2016-05-28 16:32:53",
      "thermostatTime": "2016-05-28 11:57:00",
      "utcTime": "2016-05-28 16:57:00",
      "runtime": {
        "runtimeRev": "160528165546",
        "connected": true,
        "firstConnected": "2015-08-20 21:57:53",
        "connectDateTime": "2016-05-26 08:56:18",
        "disconnectDateTime": "2016-05-26 00:00:00",
        "lastModified": "2016-05-28 16:55:46",
        "lastStatusModified": "2016-05-28 16:55:46",
        "runtimeDate": "2016-05-28",
        "runtimeInterval": 200,
        "actualTemperature": 703,
        "actualHumidity": 49,
        "desiredHeat": 670,
        "desiredCool": 810,
        "desiredHumidity": 44,
        "desiredDehumidity": 56,
        "desiredFanMode": "on"
      }
    },
    {
      "identifier": "310166836750",
      "name": "Upstairs",
      "thermostatRev": "160528162656",
      "isRegistered": true,
      "modelNumber": "athenaSmart",
      "brand": "ecobee",
      "features": "",
      "lastModified": "2016-05-28 16:26:56",
      "thermostatTime": "2016-05-28 11:57:00",
      "utcTime": "2016-05-28 16:57:00",
      "runtime": {
        "runtimeRev": "160528165523",
        "connected": true,
        "firstConnected": "2015-09-28 13:33:41",
        "connectDateTime": "2016-05-26 08:55:35",
        "disconnectDateTime": "2016-05-26 00:00:00",
        "lastModified": "2016-05-28 16:55:23",
        "lastStatusModified": "2016-05-28 16:55:23",
        "runtimeDate": "2016-05-28",
        "runtimeInterval": 201,
        "actualTemperature": 712,
        "actualHumidity": 49,
        "desiredHeat": 600,
        "desiredCool": 840,
        "desiredHumidity": 36,
        "desiredDehumidity": 60,
        "desiredFanMode": "auto"
      }
    }
  ],
  "status": {
    "code": 0,
    "message": ""
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-30 02:02:14

我认为问题在于,UrlFetchApp不支持使用get方法作为查询字符串发送有效负载。我认为这是UrlFetchAppEcobee部分设计不佳的正确设计。我通过自己在查询字符串中发送JSON,得到了一个kluge解决方案,如下所示。

代码语言:javascript
运行
复制
var URL = 'https://api.ecobee.com/1/thermostat?body='+encodeURIComponent(JSON.stringify(payload));
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37501817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档