我正在制作一个 Android 应用程序,以使用新发布的 API 与 NEST 恒温器对话。我正在遵循此页面中提供的说明:https ://developer.nest.com/documentation/how-to-auth 。
我已经让它工作到我成功收到 access_token 的地步。但是,使用该 access_token 并建立对https://developer-api.nest.com/devices.json?auth= {access_token}的 HTTP GET 请求我得到一个连接超时异常!
@mccv 这是我的代码:
private void make_REST_call(String access_token) {
String access_token_uri = "https://developer-api.nest.com/devices.json?auth="+access_token;
try {
URI uri = new URI(access_token_uri);
// Set the connection timeout value to X seconds (30000 milliseconds)
final HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 100000); // In miliseconds
httpclient = new DefaultHttpClient(httpParams);
HttpGet httpget = new HttpGet();
httpget.setURI(new URI(access_token_uri));
// Execute HTTPs GET request
Long reqTime = System.currentTimeMillis();
Log.d(tag + " make_REST_call", " reqTime time= " + reqTime);
HttpResponse response = null;
try {
response = httpclient.execute(httpget);
Log.d(tag + " make_REST_call", " response is= " + response.getEntity());
}
catch (Exception e) {
e.printStackTrace();
Log.e(tag + " make_REST_call", e.toString());
}
Long resTime = System.currentTimeMillis();
Log.d(tag + " make_REST_call", " response time= " + (resTime - reqTime));
}
catch (Exception e) {
Log.e(access_token_uri, e.toString());
e.printStackTrace();
}
}