打开天气图给我错误的请求

Open weather map gives me Bad request

我正在尝试从 android 工作室调用开放天气图 api,但它有时会给我 401 Unauthorized400 Bad request 我已经尝试更改 api 键但它不起作用虽然我也尝试改变天气 url 但它让我找不到我找不到错误但似乎网站上有问题。

Blockquote

 // Constants:
final int REQUEST_CODE = 123;
final String WEATHER_URL = "http://api.openweathermap.org/data/2.5/weather";
// App ID to use OpenWeather data
final String APP_ID = "776a27857ef2d1df5e018d2bdde968d4";
// Time between location updates (5000 milliseconds or 5 seconds)
final long MIN_TIME = 5000;
// Distance between location updates (1000m or 1km)
final float MIN_DISTANCE = 1000;

private static final String TAG = "WeatherController";

Blockquote

private void getWeatherForCurrentUser() {
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationListener = new LocationListener() {
        @Override
        public void onLocationChanged(Location location) {

            Log.d(TAG, "onLocationChanged() callback recieved");

            String longitude = String.valueOf(location.getLongitude());
            String latitude = String.valueOf(location.getLatitude());

            Log.d(TAG, "onLocationChanged: " + longitude);
            Log.d(TAG, "onLocationChanged: " + latitude);

            RequestParams params = new RequestParams();
            params.put("lat" , latitude);
            params.put("long" , longitude);
            params.put("appid" , APP_ID);
            letsDoSomeNetworking(params);

        }

Blockquote

private void letsDoSomeNetworking(RequestParams params){

    AsyncHttpClient client = new AsyncHttpClient();
    client.get(WEATHER_URL , params , new JsonHttpResponseHandler(){

        @Override

        public void onSuccess(int statusCode , Header[] headers , JSONObject response){

            Log.d(TAG, "onSuccess: " + response.toString());

        }

        @Override
        public void onFailure(int statusCode , Header[] headers , Throwable e , JSONObject response){
            Log.e(TAG, "onFailure: " + e.getMessage().toString() );
            Log.d(TAG, "onFailure: " + statusCode);

            Toast.makeText(WeatherController.this, "Request Failed" + e.getMessage().toString(), Toast.LENGTH_SHORT).show();
        }
    });

}

经度键是 lon 而不是 long。检查 api 规格 here

使用这个:

params.put("lon" , longitude);