你好,我正在尝试构建一个 Clima 应用程序,我正在使用 OpenWeatherMap
Api
从 Internet 检索天气数据。
当我在物理设备上试用该应用程序时,我收到此消息错误:
cz.msebera.android.httpclient.client.HttpResponseException: Unauthorized
我尝试生成一个新的 API key ,但出现了同样的问题。
// TODO: Add letsDoSomeNetworking(RequestParams params) here:
protected void letsDoSomeNetworking(RequestParams params) {
AsyncHttpClient client = new AsyncHttpClient();
client.get(WEATHER_URL, params, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode ,Header[] header , JSONObject response){
Log.d("Clima", "onSuccess: " + response.toString());
}
public void onFailure (int statusCode , Header[] headers , Throwable e , JSONObject response){
Log.d("Clima", "Onfailure: " + statusCode);
Log.d("Clima", "fail: " + e.toString());
Toast.makeText(WeatherController.this, "requestFialed " , Toast.LENGTH_SHORT).show();
}
});
}
最佳答案
我认为这很像你没有改变这个变量 final String APP_ID = "e******************************a";在 weathercontroller.java 上 你应该写你自己的 app_id ,你可以通过在 http://api.openweathermap.org/ ,您将在您的电子邮件中收到 app_id, key 将在 1 或 2 小时内激活。祝你好运!
关于java - cz.msebera.android.httpclient.client.HttpResponseException : Unauthorized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54154508/