Trouble retrieving the recipe from spoonulacular API (using teachable machine)



Hello! I am a student learning Mit App Inventor, i have been facing this problem with my app and my teacher cant seem to figure it out :frowning: . i am trying to make a recipe finder app for a local competition happening soon. I'm using teachable machine to recognize ingredients based on pictures and then all the recognized ingredients are supposed to be added to a list and then sent to the( spoonacular API) to then receive the ingredients but every time i try the app it shows me a blank list in the URL this is how it looked like:
image
I do apologize if my English is bad, I am still new to this community too! i also tried a lot of tutorials and videos to help me. if you need any information to help you understand my situation better, please let me know. Thank you!

What is the difference between global ingredients and global ings?

Why do you use both when you process the classification results?

1 Like

my teacher said it would be better to make the code more organized but i guess it should be better without too much unnecessary variables. thanks for the fast reply! :slight_smile: i will change it and see if it makes things better.

I changed it so there is only one variable for the ingredients. it still has the same issue though, it won't add any items to the list i think one if the problems is the teachable machine, it not doing a great job recognizing the ingredients that's why I added the check list after you take a picture of your ingredients. it's supposed to help users check the ingredients that they want if the teachable machine doesn't recognize it. i am sorry if this is confusing :frowning:

This makes no sense.

image

If you read it, you will see that it ignores the incoming responseContent in its parsing and in its loop.

1 Like

What do you advise me to do? should I set the response content at the end, so it won't be ignored? or do i change the loop? i truly appreciate your help

Web1.GotText will run recursively, since the event calls itself
When ABG said "the responseContent is being ignored", he meant you're not using it anywhere, since you're not setting the value of anything to it.

Ok so if i set a value to responseContent like a label where i can see its value it should work right? thank you buddy i will try it and show you the results :slight_smile:

Ok so I solved the list problem and now I can receive the response content . i still struggle with getting the recipe though :smiling_face_with_tear: sorry if i am a bit slow but if anyone knows what i am doing wrong can you point it out for me ? This is my code:
image



I will continue working on if there is any changes i will present them here <3

I got a sample app working up to the point where it will return a JSON list of recipes, each fully detailed, using a limited free account.

Don't worry about wasting my free account.

I have no need for recipes.

I eat whatever my wife leaves me in a bowl on the floor.


spoonacular.aia (3.0 KB)

To not waste any free accounts, here is the JSON text of a two recipe return, to study for parsing:

[{"id":654515,"title":"Pandan Smoothie","image":"https://img.spoonacular.com/recipes/654515-312x231.jpg","imageType":"jpg","usedIngredientCount":2,"missedIngredientCount":2,"missedIngredients":[{"id":2004,"amount":5.0,"unit":"","unitLong":"","unitShort":"","aisle":"Produce","name":"pandan leaves click here cut to 2\" length","original":"5 Pandan leaves click here (from my garden) cut to 2\" length","originalName":"Pandan leaves click here (from my garden) cut to 2\" length","meta":["(from my garden)"],"image":"https://img.spoonacular.com/ingredients_100x100/bay-leaves.jpg"},{"id":19296,"amount":6.0,"unit":"tablespoons","unitLong":"tablespoons","unitShort":"Tbsp","aisle":"Nut butters, Jams, and Honey","name":"honey or","original":"6 tablespoons Honey or to taste","originalName":"Honey or to taste","meta":["to taste"],"image":"https://img.spoonacular.com/ingredients_100x100/honey.png"}],"usedIngredients":[{"id":11206,"amount":100.0,"unit":"grams","unitLong":"grams","unitShort":"g","aisle":"Produce","name":"cucumber","original":"100 grams Cucumber, cut into small cubes","originalName":"Cucumber, cut into small cubes","meta":["cut into small cubes"],"image":"https://img.spoonacular.com/ingredients_100x100/cucumber.jpg"},{"id":9200,"amount":3.0,"unit":"","unitLong":"","unitShort":"","aisle":"Produce","name":"oranges","original":"3 Oranges, peeled and quartered","originalName":"Oranges, peeled and quartered","meta":["peeled","quartered"],"image":"https://img.spoonacular.com/ingredients_100x100/orange.png"}],"unusedIngredients":[],"likes":1},{"id":639512,"title":"Citrus Arugula Salad with Seared Scallops","image":"https://img.spoonacular.com/recipes/639512-312x231.png","imageType":"png","usedIngredientCount":2,"missedIngredientCount":4,"missedIngredients":[{"id":11959,"amount":2.0,"unit":"cups","unitLong":"cups","unitShort":"cup","aisle":"Produce","name":"arugula","original":"2 cups arugula","originalName":"arugula","meta":[],"image":"https://img.spoonacular.com/ingredients_100x100/arugula-or-rocket-salad.jpg"},{"id":11429,"amount":2.0,"unit":"","unitLong":"","unitShort":"","aisle":"Produce","name":"radish","original":"2 radish, thinly sliced","originalName":"radish, thinly sliced","meta":["thinly sliced"],"image":"https://img.spoonacular.com/ingredients_100x100/radishes.jpg"},{"id":11291,"amount":1.0,"unit":"","unitLong":"","unitShort":"","aisle":"Produce","name":"green onion","original":"1 green onion, chopped","originalName":"green onion, chopped","meta":["chopped"],"image":"https://img.spoonacular.com/ingredients_100x100/spring-onions.jpg"},{"id":10015172,"amount":8.0,"unit":"","unitLong":"","unitShort":"","aisle":"Seafood","name":"scallops","original":"8 scallops","originalName":"scallops","meta":[],"image":"https://img.spoonacular.com/ingredients_100x100/scallops.jpg"}],"usedIngredients":[{"id":9200,"amount":1.0,"unit":"","unitLong":"","unitShort":"","aisle":"Produce","name":"cara cars orange","original":"1 cara cars orange","originalName":"cara cars orange","meta":[],"image":"https://img.spoonacular.com/ingredients_100x100/orange.png"},{"id":10111205,"amount":0.5,"unit":"","unitLong":"","unitShort":"","aisle":"Produce","name":"persian cucumber","original":"1/2 persian cucumber (or english cucumber), thinly sliced","originalName":"persian cucumber (or english cucumber), thinly sliced","meta":["english","thinly sliced","(or cucumber)"],"extendedName":"english persian cucumber","image":"https://img.spoonacular.com/ingredients_100x100/english-cucumber.png"}],"unusedIngredients":[],"likes":7}]

and here is a NotePad++ prettified version, to expose the nesting better:

[
    {
        "id": 654515,
        "image": "https://img.spoonacular.com/recipes/654515-312x231.jpg",
        "imageType": "jpg",
        "likes": 1,
        "missedIngredientCount": 2,
        "missedIngredients": [
            {
                "aisle": "Produce",
                "amount": 5.0,
                "id": 2004,
                "image": "https://img.spoonacular.com/ingredients_100x100/bay-leaves.jpg",
                "meta": [
                    "(from my garden)"
                ],
                "name": "pandan leaves click here cut to 2\" length",
                "original": "5 Pandan leaves click here (from my garden) cut to 2\" length",
                "originalName": "Pandan leaves click here (from my garden) cut to 2\" length",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            },
            {
                "aisle": "Nut butters, Jams, and Honey",
                "amount": 6.0,
                "id": 19296,
                "image": "https://img.spoonacular.com/ingredients_100x100/honey.png",
                "meta": [
                    "to taste"
                ],
                "name": "honey or",
                "original": "6 tablespoons Honey or to taste",
                "originalName": "Honey or to taste",
                "unit": "tablespoons",
                "unitLong": "tablespoons",
                "unitShort": "Tbsp"
            }
        ],
        "title": "Pandan Smoothie",
        "unusedIngredients": [
        ],
        "usedIngredientCount": 2,
        "usedIngredients": [
            {
                "aisle": "Produce",
                "amount": 100.0,
                "id": 11206,
                "image": "https://img.spoonacular.com/ingredients_100x100/cucumber.jpg",
                "meta": [
                    "cut into small cubes"
                ],
                "name": "cucumber",
                "original": "100 grams Cucumber, cut into small cubes",
                "originalName": "Cucumber, cut into small cubes",
                "unit": "grams",
                "unitLong": "grams",
                "unitShort": "g"
            },
            {
                "aisle": "Produce",
                "amount": 3.0,
                "id": 9200,
                "image": "https://img.spoonacular.com/ingredients_100x100/orange.png",
                "meta": [
                    "peeled",
                    "quartered"
                ],
                "name": "oranges",
                "original": "3 Oranges, peeled and quartered",
                "originalName": "Oranges, peeled and quartered",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            }
        ]
    },
    {
        "id": 639512,
        "image": "https://img.spoonacular.com/recipes/639512-312x231.png",
        "imageType": "png",
        "likes": 7,
        "missedIngredientCount": 4,
        "missedIngredients": [
            {
                "aisle": "Produce",
                "amount": 2.0,
                "id": 11959,
                "image": "https://img.spoonacular.com/ingredients_100x100/arugula-or-rocket-salad.jpg",
                "meta": [
                ],
                "name": "arugula",
                "original": "2 cups arugula",
                "originalName": "arugula",
                "unit": "cups",
                "unitLong": "cups",
                "unitShort": "cup"
            },
            {
                "aisle": "Produce",
                "amount": 2.0,
                "id": 11429,
                "image": "https://img.spoonacular.com/ingredients_100x100/radishes.jpg",
                "meta": [
                    "thinly sliced"
                ],
                "name": "radish",
                "original": "2 radish, thinly sliced",
                "originalName": "radish, thinly sliced",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            },
            {
                "aisle": "Produce",
                "amount": 1.0,
                "id": 11291,
                "image": "https://img.spoonacular.com/ingredients_100x100/spring-onions.jpg",
                "meta": [
                    "chopped"
                ],
                "name": "green onion",
                "original": "1 green onion, chopped",
                "originalName": "green onion, chopped",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            },
            {
                "aisle": "Seafood",
                "amount": 8.0,
                "id": 10015172,
                "image": "https://img.spoonacular.com/ingredients_100x100/scallops.jpg",
                "meta": [
                ],
                "name": "scallops",
                "original": "8 scallops",
                "originalName": "scallops",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            }
        ],
        "title": "Citrus Arugula Salad with Seared Scallops",
        "unusedIngredients": [
        ],
        "usedIngredientCount": 2,
        "usedIngredients": [
            {
                "aisle": "Produce",
                "amount": 1.0,
                "id": 9200,
                "image": "https://img.spoonacular.com/ingredients_100x100/orange.png",
                "meta": [
                ],
                "name": "cara cars orange",
                "original": "1 cara cars orange",
                "originalName": "cara cars orange",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            },
            {
                "aisle": "Produce",
                "amount": 0.5,
                "extendedName": "english persian cucumber",
                "id": 10111205,
                "image": "https://img.spoonacular.com/ingredients_100x100/english-cucumber.png",
                "meta": [
                    "english",
                    "thinly sliced",
                    "(or cucumber)"
                ],
                "name": "persian cucumber",
                "original": "1/2 persian cucumber (or english cucumber), thinly sliced",
                "originalName": "persian cucumber (or english cucumber), thinly sliced",
                "unit": "",
                "unitLong": "",
                "unitShort": ""
            }
        ]
    }
]

Thank you so much you are a life saver i can now receive the recipes and everything is going well you are an angel. :dizzy: :sunflower: :blossom:I just hope i can get the app to translate the Json text into normal text in time. <33 @ABG

Once I am done with the competition i will post the app .aix in this conversation so you can see it :slight_smile: <33

I have been trying to translate the JSON text for the recipes that I receive from spoonacular and i keep getting the same error can anyone explain to me what it means ?


and this is my code :
image
I also tried to separate it in pairs (keys and values) like I have seen many tutorials and people too but the JSON text that I receive is not in pairs and I don't really understand alot about JSON as my teacher didn't teach me about it but I tried to learn from here : Using Web APIs with JSON (mit.edu) and it was helpful :slight_smile: :blossom: :dizzy: but i only managed to understand the basics . so if anyone can explain the problem that i am going through or provide me with any link to a useful tutorial i will be very grateful <33

can you paste here exactly what you are receiving in the responseContent (before any conversion)?

of course, buddy! here it is:



:blossom: :blossom: :blossom:

Not a screenshot of your responseContent, but the content of the responseContent. Check here how do it and then paste here the received response:
How to show raw responseContent from your app when debugging - Tutorials and Guides - MIT App Inventor Community

like this?
[{"id":654515,"image":"https://img.spoonacular.com/recipes/654515-312x231.jpg","imageType":"jpg","likes":1,"missedIngredientCount":2,"missedIngredients":[{"aisle":"Produce","amount":5,"id":2004,"image":"https://img.spoonacular.com/ingredients_100x100/bay-leaves.jpg","meta":["(from my garden)"],"name":"pandan leaves click here cut to 2" length","original":"5 Pandan leaves click here (from my garden) cut to 2" length","originalName":"Pandan leaves click here (from my garden) cut to 2" length","unit":"","unitLong":"","unitShort":""},{"aisle":"Nut butters, Jams, and Honey","amount":6,"id":19296,"image":"https://img.spoonacular.com/ingredients_100x100/honey.png","meta":["to taste"],"name":"honey or","original":"6 tablespoons Honey or to taste","originalName":"Honey or to taste","unit":"tablespoons","unitLong":"tablespoons","unitShort":"Tbsp"}],"title":"Pandan Smoothie","unusedIngredients":,"usedIngredientCount":2,"usedIngredients":[{"aisle":"Produce","amount":100,"id":11206,"image":"https://img.spoonacular.com/ingredients_100x100/cucumber.jpg","meta":["cut into small cubes"],"name":"cucumber","original":"100 grams Cucumber, cut into small cubes","originalName":"Cucumber, cut into small cubes","unit":"grams","unitLong":"grams","unitShort":"g"},{"aisle":"Produce","amount":3,"id":9200,"image":"https://img.spoonacular.com/ingredients_100x100/orange.png","meta":["peeled","quartered"],"name":"oranges","original":"3 Oranges, peeled and quartered","originalName":"Oranges, peeled and quartered","unit":"","unitLong":"","unitShort":""}]}, {"id":639512,"image":"https://img.spoonacular.com/recipes/639512-312x231.png","imageType":"png","likes":7,"missedIngredientCount":4,"missedIngredients":[{"aisle":"Produce","amount":2,"id":11959,"image":"https://img.spoonacular.com/ingredients_100x100/arugula-or-rocket-salad.jpg","meta":,"name":"arugula","original":"2 cups arugula","originalName":"arugula","unit":"cups","unitLong":"cups","unitShort":"cup"},{"aisle":"Produce","amount":2,"id":11429,"image":"https://img.spoonacular.com/ingredients_100x100/radishes.jpg","meta":["thinly sliced"],"name":"radish","original":"2 radish, thinly sliced","originalName":"radish, thinly sliced","unit":"","unitLong":"","unitShort":""},{"aisle":"Produce","amount":1,"id":11291,"image":"https://img.spoonacular.com/ingredients_100x100/spring-onions.jpg","meta":["chopped"],"name":"green onion","original":"1 green onion, chopped","originalName":"green onion, chopped","unit":"","unitLong":"","unitShort":""},{"aisle":"Seafood","amount":8,"id":10015172,"image":"https://img.spoonacular.com/ingredients_100x100/scallops.jpg","meta":,"name":"scallops","original":"8 scallops","originalName":"scallops","unit":"","unitLong":"","unitShort":""}],"title":"Citrus Arugula Salad with Seared Scallops","unusedIngredients":,"usedIngredientCount":2,"usedIngredients":[{"aisle":"Produce","amount":1,"id":9200,"image":"https://img.spoonacular.com/ingredients_100x100/orange.png","meta":,"name":"cara cars orange","original":"1 cara cars orange","originalName":"cara cars orange","unit":"","unitLong":"","unitShort":""},{"aisle":"Produce","amount":0.5,"extendedName":"english persian cucumber","id":10111205,"image":"https://img.spoonacular.com/ingredients_100x100/english-cucumber.png","meta":["english","thinly sliced","(or cucumber)"],"name":"persian cucumber","original":"1/2 persian cucumber (or english cucumber), thinly sliced","originalName":"persian cucumber (or english cucumber), thinly sliced","unit":"","unitLong":"","unitShort":""}]}]

1 Like

It seems it is not a well formed JSON...

also fields with no values:
image

image

1 Like

I don't know what to do with it, this is exactly how i received it from the spoonacular API . is the issue with the Api itself or my app :frowning: