I copied the example request that was provided from the site but I keep getting an unhandled exception error on the same line that I just copied. What am I doing incorrectly? The line that is causing the error is below.
// These code snippets use an open-source library.
HttpResponse<JsonNode> response = Unirest.get(“https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/extract?forceExtraction=false&url=http%3A%2F%2Fallrecipes.com%2Frecipe%2F27005%2Fturkey-salad%2F”)
.header(“X-Mashape-Key”, {my_key})
.asJson();
Also, how would I grab specific aspects of the Recipe to load into my own Recipe.java class? For example: I would want to add all ingredients returned to my own Recipe.java class to be used in GUI later. How would I do that with the HTTPResponse<JsonNode> object that is returned?
Join in the discussion - add comment below:
Unfortunately I’m the wrong person to ask as that is a general Unirest issue. I’d suggest you write the mashape support, those guys are very responsive and helpful. They can most likely help you out.
So I am trying to make the API calls a different way and I was just wondering how to format the URL?
Basically I need to know where to put “X-Mashape-Key” and {my actual key} in the URL: “https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/extract?forceExtraction=false&url=http://allrecipes.com/recipe/27005/turkey-salad”
http://blog.mashape.com/using-unirest-java-for-your-android-projects/
I have visited this page multiple times but the instructions are for Eclipse and I am using Android Studio. Also when attempting to install Maven, there is not a /bin folder located in apache-maven-3.3.3. There is one located in apache-maven-3.3.3/apache-maven/src/ but when using that path for the rest of the instructions, running mvn -v returned an error saying “Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher”
Makes sense.
Another BIG issue I am having is that Unirest-Java is not compatible with Android Studio as far as I can tell. The error I am getting is java.lang.NoClassDefFoundError: org.apache.http.client.config.RequestConfig.
I have added all of the proper dependencies for Unirest and continue to get this error. Online sources are saying that Uni-rest just does not function with Android devices?
Is there any way you could help this? Any .jar file that could solve this problem?
Hey SmartChef,
please try to not URL Encode the Parameter after url, so try http://allrecipes.com/recipe/… instead of the encoded version. Mashape generates that code and I have no influence on that.
Your response for Java will contain a JsonNode which has all the aspects that you can query in the Json and put into your own class.
Does that make sense?
Maybe that helps too: http://stackoverflow.com/questions/23630681/how-to-parse-json-results-from-unirest-call
Best,
David