I was trying to use the Amadeus Airport Autocomplete API. However it keeps returning an empty response. I'm just getting started with requesting data from API's
so input is really appreciated.
The JSONdata looks like as below:
[
{
"value": "ROC",
"label": "Greater Rochester International Airport [ROC]"
},
{
"value": "MEE",
"label": "La Roche - Maré Island Airport [MEE]"
},
{
"value": "CAY",
"label": "Cayenne - Rochambeau [CAY]"
}
]
My code is as follows:
private void RequestParams(){
RequestParams params=new RequestParams();
params.put("apikey",API_KEYTRUE);
params.put("term",keyw);
letsDoSomeNetworking(params);
}
private void letsDoSomeNetworking(RequestParams params){
Log.d("PlanSky","Entered Letsdosomenetworking");
//Async Http
AsyncHttpClient client =new AsyncHttpClient();
client.get(FIN_URL,params,new JsonHttpResponseHandler(){
@Override
public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
Log.d("PlanSky","Success");
try {
Log.d("PlanSky", "response" +response);
}
catch(Exception e){
Log.d("PlanSky","Exception"+e);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
Log.d("PlanSky","Error Encountered");
}
});
}
I tried requesting a JSONobject
from the response JSONObject obj=response.getJSONObject(0);
but it did not return anything either
The logcat output is as follows:
D/PlanSky: Button Clicked
D/PlanSky: Entered Letsdosomenetworking
D/PlanSky: Success
D/PlanSky: response[]
This is most likely an issue with your input data and not the API itself. If you provide an invalid term, it is normal that the API returns an empty list as there are no airports matching your term. Try to play with the shooter to reproduce this behavior, for example if term = "" or "@" you will see an empty response.