1

我正在制作一个 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();
    }
}
4

2 回答 2

1

我发现出了什么问题。

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

于 2014-07-01T20:36:33.140 回答
0

您可以使用以下命令生成更多调试:

final Config defaultConfig = Firebase.getDefaultConfig
defaultConfig.setLogLevel(Logger.Level.DEBUG)
于 2014-07-01T16:56:40.373 回答