You need to send a json request using the Curl utility to the service for recognizing emotions

Service https://api.projectoxford.ai/emotion/v1.0/recognize , which recognizes the emotions on the face of a person in the photo.

The description shows examples for different PL and for Curl:

curl -v -X POST "https://api.projectoxford.ai/emotion/v1.0/recognize" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: {subscription key}" --data-ascii "{body}" 

{body} must be an image url.

key - a unique key for access that can be obtained during registration. I have such a key, I will provide 1 key, then I will generate it again when the question closes.

9cd1728ed38c49278236aae4b56d9ade

The key is working, you can use.

An example of my request:

 curl -v -X POST "https://api.projectoxford.ai/emotion/v1.0/recognize" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: 0022db3b0ff34391b6e60dea801086bc" --data-ascii "{"url": "http://images.webpark.ru/uploads54/110818/Portraits_04.jpg"}" 

My answer:

 * Hostname was NOT found in DNS cache * Trying 40.68.24.134... * Connected to api.projectoxford.ai (40.68.24.134) port 443 (#0) * successfully set certificate verify locations: * CAfile: none CApath: /etc/ssl/certs * SSLv3, TLS handshake, Client hello (1): * SSLv3, TLS handshake, Server hello (2): * SSLv3, TLS handshake, CERT (11): * SSLv3, TLS handshake, Server key exchange (12): * SSLv3, TLS handshake, Server finished (14): * SSLv3, TLS handshake, Client key exchange (16): * SSLv3, TLS change cipher, Client hello (1): * SSLv3, TLS handshake, Finished (20): * SSLv3, TLS change cipher, Client hello (1): * SSLv3, TLS handshake, Finished (20): * SSL connection using ECDHE-RSA-AES256-SHA384 * Server certificate: * subject: CN=*.projectoxford.ai * start date: 2015-04-14 04:15:32 GMT * expire date: 2017-04-13 04:15:32 GMT * subjectAltName: api.projectoxford.ai matched * issuer: C=US; ST=Washington; L=Redmond; O=Microsoft Corporation; OU=Microsoft IT; CN=Microsoft IT SSL SHA2 * SSL certificate verify ok. > POST /emotion/v1.0/recognize HTTP/1.1 > User-Agent: curl/7.35.0 > Host: api.projectoxford.ai > Accept: */* > Content-Type: application/json > Ocp-Apim-Subscription-Key: 0022db3b0ff34391b6e60dea801086bc > Content-Length: 65 > * upload completely sent off: 65 out of 65 bytes < HTTP/1.1 400 Bad Request < Cache-Control: no-cache < Pragma: no-cache < Content-Length: 60 < Content-Type: application/json; charset=utf-8 < Expires: -1 < X-Powered-By: ASP.NET < apim-request-id: b7f40e3a-6205-4a71-9cd8-9f0e9f9f5d0e < Date: Mon, 01 Aug 2016 16:31:47 GMT < * Connection #0 to host api.projectoxford.ai left intact {"error":{"code":"BadBody","message":"JSON parsing error."}} 

As you can see, nothing comes out, because The answer should be in the format:

  [ { "faceRectangle": { "left": 68, "top": 97, "width": 64, "height": 97 }, "scores": { "anger": 0.00300731952, "contempt": 5.14648448E-08, "disgust": 9.180124E-06, "fear": 0.0001912825, "happiness": 0.9875571, "neutral": 0.0009861537, "sadness": 1.889955E-05, "surprise": 0.008229999 } } ] 

    1 answer 1

    Double quotes that are used before and after the request body in the --data-ascii parameter replace with single quotes.

     --data-ascii '{"url": "http://images.webpark.ru/uploads54/110818/Portraits_04.jpg"}' 
    • Thank! It worked. And you could not explain why single quotes? And why is this not in the example? - Mr.Ki.D.
    • Everything is simple, in fact you could replace internal quotes with single quotes, and external quotes with double quotes, and then it would also work. The problem is that if you use one type of quotation marks everywhere, they are cut off when sent, and the server receives the value: "{url: images.webpark.ru/uploads54/110818/Portraits_04.jpg }", in which there are no quotes according to the standard json. - Firepro
    • Did I understand correctly that all quotes were cut off altogether? Then it is not clear why you cannot put single quotes here and there, or double quotes, as it was. - Mr.Ki.D.
    • one
      You have the first quotes (single quotes) to show the command line what data to take. The second and further (double) are used in the request body for JSON. Bash does not understand simply, until what point to take data. The first quotation mark, the character} and again this quotation mark, so, in fact, the data is here. But in Bash it somehow happens by the clever one and it cuts off the inner quotes altogether. You could use double quotes everywhere if you used screening in the request body: --data-ascii "{\" url \ ": \" images.webpark.ru/uploads54/110818/Portraits_04.jpg \ "}" - Firepro
    • one
      Simply using different quotes eliminates the need for shielding them in the body. - Firepro