I am trying to use cloudsight.ai api in my android app using image from url, The cloudsight.ai api from mashape platform
When I built the app there is no problem but when I run it and click the button it crashed.
Here is the code of request using unirest library:
try {
HttpResponse<JsonNode> sent = Unirest.post("https://camfind.p.mashape.com/image_requests")
.header("X-Mashape-Key", "key")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept", "application/json")
.field("image_request[language]", "en")
.field("image_request[locale]", "en_US")
.field("image_request[remote_image_url]", img)
.asJson();
req_body=sent.getBody().toString();
} catch (UnirestException e) {
}
And here the code of response :
try {
JSONObject json = new JSONObject(req_body);
token = json.getString("token");
} catch (JSONException e) {
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
}
String res_path = "https://camfind.p.mashape.com/image_responses/" + token;
try {
HttpResponse<JsonNode> response = Unirest
.get(res_path)
.header("X-Mashape-Key", "key")
.header("Accept", "application/json")
.asJson();
result=response.getBody().toString();
} catch (UnirestException e) {
}
Toast.makeText(Main3Activity.this,result,Toast.LENGTH_SHORT).show();
}
How to solve this problem?