문제

I am using CamFind API for image recognition in my app. I am following CamFind Tutorial but stuck at how to get response from that API after posting data? How you got my question.

도움이 되었습니까?

해결책

try this code

try {
        HttpResponse<JsonNode> request = Unirest
                .post("https://camfind.p.mashape.com/image_requests")
                .header("X-Mashape-Authorization",
                        "A0MYOpCsdfasdgadfadafgdj7vsdfe")
                .field("image_request[locale]", "en_US")
                .field("image_request[image]",
                        new File("your Image path")).asJson();

        String body =  request.getBody().toString(); 
        Log.v("body", body);
    } catch (UnirestException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

now the body string contain the json response String with a Token variable inside it
and to get the recognition name do the same again, but remove the fields and add the Token value after the url so it will look like this: https://camfind.p.mashape.com/image_requests/(Token Vlaue)

now the body string will contain the name value

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top