2016-05-28 5 views
0

Ecobee APIを使用して、私のサーモスタットに話をしようとします。下のコードでは、jsonの値は"{ "status": { "code": 0, "message": "" } }"です。正確で完全な応答を得るには、後でcurlの結果を参照してください。何らかの理由responseについてはEcobee:Google Appsのスクリプトを使用して応答を返すのみ部分的な結果

は唯一のサーバー(pagethermostatList、およびstatus)によって返される3件の結果のうち、最後の要素(status)を取得しています。

私には何が欠けていますか?

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を使用して::私は完全な結果を得る

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\}\}' 

次のように

のGoogle Apps Scriptがあります。

{ 
    "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": "" 
    } 
} 

答えて

2

UrlFetchAppは、getメソッドをクエリ文字列として使用してペイロードを送信することをサポートしていないと思います。私はこれがUrlFetchApppoor design on the part of the Ecobee APIの正しいデザインだと考えています。私は、以下のように自分自身でクエリ文字列にJSONを送信することで回避策を作りました。

var URL = 'https://api.ecobee.com/1/thermostat?body='+encodeURIComponent(JSON.stringify(payload)); 
関連する問題