[英]Open weather map gives me Bad request
我正在嘗試從android studio調用開放式天氣地圖api,但有時它會給我401 Unauthorized
或400 Bad request
我試圖更改api密鑰,但是它不起作用,但我也試圖更改天氣url,但找不到我我找不到錯誤,但似乎網站上有問題。
大段引用
// 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";
大段引用
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);
}
大段引用
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();
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.