Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get servings? #7

Open
ariefpurnamamuharram opened this issue Jun 2, 2018 · 12 comments
Open

How to get servings? #7

ariefpurnamamuharram opened this issue Jun 2, 2018 · 12 comments

Comments

@ariefpurnamamuharram
Copy link

Hello,
Can you help me how to get serving details?
Thank you.

@ranesr ranesr added the question label Jun 4, 2018
@ariefpurnamamuharram
Copy link
Author

Anyone can help me, please?

@ranesr
Copy link
Collaborator

ranesr commented Jun 9, 2018

@ariefpurnamamuharram Recipe has Serving object in it from which you can get all the details. Also Food has an array of Service objects which give details about all kinds of different servings.

May I know which Recipe/Food are you trying to retrieve?

@ariefpurnamamuharram
Copy link
Author

No, it is not about recipe.
Let me assume Indomie. I want to get the serving details of Indomie, just like Calories, Natrium, etc. How to do that? Can you give me an example code?
Thank you @ranesr

@ranesr
Copy link
Collaborator

ranesr commented Jun 9, 2018

In that case, you are looking for Food.
You can use this code:

String key = "ENTER YOUR KEY HERE";
String secret = "ENTER YOUR SECRET HERE";
FatsecretService service = new FatsecretService(key, secret);
String query = "Indomie";
Response<CompactFood> response = service.searchFoods(query);
List<CompactFood> results = response.getResults();
for (CompactFood food: results) {
    Food f = service.getFood(food.getId());
    if (f.getServings() != null && f.getServings().size() > 0) {
        // The following line will give you Serving object.
        Serving serving = f.getServings().get(0);
        System.out.println("servingDescription: " + serving.getServingDescription());
        System.out.println("servingUrl: " + serving.getServingUrl());
        System.out.println("calories: " + serving.getCalories());
    }
}

You can find more about Serving object here. There is a lot of information you will get from this object, like calories, carbohydrates, proteins, etc.

@ariefpurnamamuharram
Copy link
Author

I try to implement the code, but I encountered some errors. What should I do? @ranesr
Thank you.

screenshot from 2018-06-11 13-36-09

@ariefpurnamamuharram
Copy link
Author

ariefpurnamamuharram commented Jun 11, 2018

@ranesr can you help me by giving me the full codes of the example?
Thank you

@ranesr
Copy link
Collaborator

ranesr commented Jun 12, 2018

@ariefpurnamamuharram Have you added this to your build.gradle file?

@ariefpurnamamuharram
Copy link
Author

Yes, I have. But it doesn't resolve my problem. @ranesr

@ariefpurnamamuharram
Copy link
Author

ariefpurnamamuharram commented Jun 24, 2018

Any solution for my problem, please? @ranesr
Thank you

@ranesr
Copy link
Collaborator

ranesr commented Jun 24, 2018

@ariefpurnamamuharram Can you share your FoodSearchActivity.java file?

@ariefpurnamamuharram
Copy link
Author

@ranesr
I just copy the code that you have give it to me.

screenshot from 2018-07-12 02-40-32

@ariefpurnamamuharram
Copy link
Author

@ranesr @ohdihe could anyone please help me?
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants