We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to use Client for the first time and having issues connecting to a specific API (api.imagga.com).
I am trying to reproduce the sample code from their docs (http://docs.imagga.com/index.html) that looks like this and provides a response:
curl -H "Authorization: Basic YWNjXzYzY2Q2NzQ3YmRjMDgzYzo5N2Q5OTBmNzllNDkzYjUwOGJlODdjYWRmODRlNmFhNg==" "http://api.imagga.com/v1/tagging?url=http://playground.imagga.com/static/img/example_photos/japan-605234_1280.jpg"
I am hitting a wall when I start making requests as the client is simply returning "null" and not providing any errors to work with. I am hoping that someone with more experience working with servers and APIs in Processing can help me get this up and running. Here's what I've got:
import processing.net.*;
String encodedAuth = "YWNjXzYzY2Q2NzQ3YmRjMDgzYzo5N2Q5OTBmNzllNDkzYjUwOGJlODdjYWRmODRlNmFhNg==";
Client client;
void setup() {
client = new Client(this, "api.imagga.com", 80);
client.write("GET HTTP/1.0 \r\n");
client.write("authorization: Basic " + encodedAuth);
client.write("host: api.imagga.com\r\n");
client.write("/v1/tagging?url=http%3A%2F%2Fplayground.imagga.com%2Fstatic%2Fimg%2Fexample_photo.jpg\r\n");
client.write("\r\n"); // indicates end of request?
String dataIn = client.readString();
println(dataIn);
}
void draw() {
}
Answers
You miss a \r\n at the end of the authorization line.
Thanks @PhiLho. That was certainly an issue, and has helped move me closer to getting this working, but I'm still in the weeds. It also points to one of the problems I'm having with the Client object… I can't see what is happening. How can I get more output to the console to ensure that I'm sending rational commands to the server?
I'm at the point where I'm receiving "HTTP/1.1 400 BAD_REQUEST", but I still feel as if I'm operating blind.
Please replace encodedAuth with your own encoded string.
I'm getting a 401 unauthorized using what's below. Maybe just need a new bearer token?