Hi all.
I have tried to resolve this to no avail. I just don't know what I'm doing wrong. I really hope someone out there can point me in the right direction. Apologies if my use of terminology is occasionally bogus below - network stuff is not my usual bag.
Basically, I'm trying to use the Microsoft Emotion API in Processing: https://dev.projectoxford.ai/docs/services/5639d931ca73072154c1ce89/operations/563b31ea778daf121cc3a5fa It requires API key authentication and HTTP headers as a POST request. I found the HTTP requests library (by Shiffman et al) which apparently takes the pain away (heh) and built a test example below:
import http.requests.*;
PostRequest post;
void setup() {
size(400, 400);
makeRequest();
//println("Reponse Content: " + post.getContent());
//println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
JSONObject response = parseJSONObject(post.getContent());
println(response);
}
void makeRequest() {
post = new PostRequest("https://" + "westus.api.cognitive.microsoft.com/emotion/v1.0/recognize");
post.addHeader("Content-Type", "application/json");
post.addHeader("Ocp-Apim-Subscription-Key", MyAPIkeyGoesHere);
post.addData("url", "http://" + "www.boro.gr/contentfiles_2016/psyxologia/thymos/axaaamm.jpg");
post.send();
}
What I should get back is a JSON file that looks like this:
{
"faceRectangle": {
"height": 216,
"left": 225,
"top": 90,
"width": 216
},
"scores": {
"anger": 9.38430444E-11,
"contempt": 3.36862873E-12,
"disgust": 4.649468E-11,
"fear": 1.913897E-11,
"happiness": 1.0,
"neutral": 7.306441E-11,
"sadness": 1.65613755E-11,
"surprise": 2.97461256E-09
}
}
... but what I get is this:
{"error": {
"code": "BadBody",
"message": "JSON parsing error."
}}
Anybody know what's going on? Also, if I was wanting to upload an image locally, how would I do that? Apologies for lameness, but am very grateful for any help. Thanks.
Kind regards, Paul.