GithubHelp home page GithubHelp logo

How to get servings? about fatsecret4j HOT 12 OPEN

fatsecret avatar fatsecret commented on June 9, 2024
How to get servings?

from fatsecret4j.

Comments (12)

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

Anyone can help me, please?

from fatsecret4j.

ranesr avatar ranesr commented on June 9, 2024

@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?

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

from fatsecret4j.

ranesr avatar ranesr commented on June 9, 2024

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.

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

from fatsecret4j.

ranesr avatar ranesr commented on June 9, 2024

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

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

from fatsecret4j.

ranesr avatar ranesr commented on June 9, 2024

@ariefpurnamamuharram Can you share your FoodSearchActivity.java file?

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

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

from fatsecret4j.

ariefpurnamamuharram avatar ariefpurnamamuharram commented on June 9, 2024

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

from fatsecret4j.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.