Call API via Post with JS or JQ [closed]

-1

Personally someone could help me by giving an example of how to consume an API that returns a JSON like this API below:

link

Personally I implemented the code below can help me is not returning anything nor error.

$('.teste').click(function() {


      $.ajax({
        type:"post",
        url:"https://api-us.faceplusplus.com/facepp/v3/detect",
        data: {
            api_key: 'M...s',
            api_secret: 'y...0',
            url: 'http://emotions.pushsistemas.com.br/web/train/mmi/alegria/1.png'
        },
        success: function(data) {
            console.log("saida",JSON.stringify(data));
        },
        dataType: 'jsonp',
    });

  });
    
asked by anonymous 04.12.2018 / 20:47

1 answer

2

1) According to the documentation in the data to pass% of image%, the property must be URL and not image_url .

2) Change the type of url from dataType to jsonp

Final code:

$.ajax({
    type:"post",
    url:"https://api-us.faceplusplus.com/facepp/v3/detect",
    data: {
        api_key: 'MgfOZx5IZCuocbZ5wMmKCdZkd7P0mPhs',
        api_secret: 'ymFeQjguF6lGA8oLlneuAHMtdhq1QSA0',
        image_url: 'http://emotions.pushsistemas.com.br/web/train/mmi/alegria/1.png'
    },
    success: function(data) {
        console.log("saida",JSON.stringify(data));
    },
    dataType: 'application/json',
});'

I took the test and got the following result:

{
    "image_id": "CxX5j9mXrorIFJ/336gFbQ==",
    "request_id": "1543955895,b7599a1a-e67b-4298-9dc5-566c3d13758e",
    "time_used": 1707,
    "faces": [{
        "face_rectangle": {
            "width": 296,
            "top": 316,
            "left": 152,
            "height": 296
        },
        "face_token": "e17f055212b25d1837004bff48d21226"
    }]
}
  

    
04.12.2018 / 21:42