gpt4 book ai didi

java - Nest 恒温器 API : Connection time out after establishing a request using the retrieved access_token

转载 作者:行者123 更新时间:2023-11-30 02:49:12 27 4
gpt4 key购买 nike

我正在制作一个 Android 应用程序,使用新发布的 API 与恒温器 NEST 通信。我正在按照此页面中提供的说明进行操作:https://developer.nest.com/documentation/how-to-auth .

我已经让它运行到我成功收到 access_token 的地步。但是使用该 access_token 并建立对 https://developer-api.nest.com/devices.json?auth= 的 HTTP GET 请求{access_token} 我收到连接超时异常!

@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();
}
}

最佳答案

我想出了问题所在。

实际上在我访问端口被阻止的服务器的路上有防火墙。通过将我的 httpclient 重定向到代理,我绕过了它,所以问题就解决了。

关于java - Nest 恒温器 API : Connection time out after establishing a request using the retrieved access_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24501369/

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