fatsecret4j

You can use this java/android client for consuming food.get(), foods.search(), recipe.get(), and recipes.search() methods provided by Fatsecret REST API

Java Documentation

Want your Java app to make calls to fatsecret rest api? fatsecret4j is a Java library that can enable your app to communicate with fatsecret api.

You can use this library by downloading it here or doing the following step:

Add the dependency to your Maven POM
							
<dependency>
	<groupId>com.fatsecret4j</groupId>
	<artifactId>fatsecret-platform</artifactId>
	<version>2.0</version>
</dependency>
							
						
foods.search

You will need to initialize FatsecretService with your Fatsecret Application Consumer Key and associated Consumer Secret and you are good to search food items. You have to use searchFoods method from FatsecretService in order to get a list of food items.

Response

maxResults

maximum number of results (always 50)

totalResults

total number of results

pageNumber

zero-based offset into the results for the query

results

list of summary of food items

Example

							
package com.yourpackage;
import com.fatsecret.platform.services.FatsecretService;
import com.fatsecret.platform.model.CompactFood;
import java.util.List;
...
public class YourService {
	public void searchFoodItems() {
		String key = "Replace this by your Application Consumer Key";
		String secret = "Replace this by your Consumer Secret";
		FatsecretService service = new FatsecretService(key, secret);
		
		String query = "pasta"; //Your query string
		Response<CompactFood> response = service.searchFoods(query);
		//This response contains the list of food items at zeroth page for your query
		
		List<CompactFood> results = response.getResults();
		//This list contains summary information about the food items
		
		Response<CompactFood> responseAtPage3 = service.searchFoods(query, 3);
		//This response contains the list of food items at page number 3 for your query
		//If total results are less, then this response will have empty list of the food items		
	}
}
							
						
food.get

You will need to initialize FatsecretService with your Fatsecret Application Consumer Key and associated Consumer Secret and you are good to get a food item. You have to use getFood method from FatsecretService in order to get detailed information of the food item.

Response

id

the unique food identifier

name

the name of the food, not including the brand name; E.G.: "Instant Oatmeal"

type

type of the food - indicates whether the food is a brand or generic item

description

a short description of the food item(if available)

url

URL of this food item on fatsecret website

brandName

the brand name

servings

a list of all servings indicating nutrient values for each serving type

Example

							
package com.yourpackage;
import com.fatsecret.platform.services.FatsecretService;
import com.fatsecret.platform.model.Food;
...
public class YourService {
	public void getFoodItem() {
		String key = "Replace this by your Application Consumer Key";
		String secret = "Replace this by your Consumer Secret";
		FatsecretService service = new FatsecretService(key, secret);
		
		Long id = 319489L;
		Food food = service.getFood(id);
		//This food object contains detailed information about the food item
	}
}
							
						
recipes.search

You will need to initialize FatsecretService with your Fatsecret Application Consumer Key and associated Consumer Secret and you are good to search recipe items. You have to use searchRecipes method from FatsecretService in order to get a list of recipe items.

Response

maxResults

maximum number of results (always 50)

totalResults

total number of results

pageNumber

zero-based offset into the results for the query

results

list of summary of recipe items

Example

							
package com.yourpackage;
import com.fatsecret.platform.services.FatsecretService;
import com.fatsecret.platform.model.CompactRecipe;
import java.util.List;
...
public class YourService {
	public void searchRecipeItems() {
		String key = "Replace this by your Application Consumer Key";
		String secret = "Replace this by your Consumer Secret";
		FatsecretService service = new FatsecretService(key, secret);
		
		String query = "pasta"; //Your query string
		Response<CompactRecipe> response = service.searchRecipes(query);
		//This response contains the list of recipe items at zeroth page for your query
		
		List<CompactRecipe> results = response.getResults();
		//This list contains summary information about the recipe items
		
		Response<CompactRecipe> responseAtPage2 = service.searchRecipes(query, 2);
		//This response contains the list of recipe items at page number 2 for your query
		//If total results are less, then this response will have empty list of the recipe items		
	}
}
							
						
recipe.get

You will need to initialize FatsecretService with your Fatsecret Application Consumer Key and associated Consumer Secret and you are good to get a recipe item. You have to use getRecipe method from FatsecretService in order to get detailed information of the recipe item.

Response

id

the unique recipe identifier

name

the name of the recipe

description

a short description of the recipe item(if available)

url

URL of this food item on fatsecret website

images

a list of URLs of all the images for this recipe on fatsecret website

categories

a list of the categories that the recipe is classified under; E.G.: "Seafood"

cookingTime

the time in minutes to cook the recipe (where available)

preparationTime

the time in minutes to prepare the recipe (where available)

ingredients

a list of the ingredients that make up the recipe

directions

a list of the directions/steps involved in creating the recipe

rating

the overall average rating of a recipe from fatsecret members out of five

numberOfServings

the number of servings the recipe is intended for

serving

the complete nutritional information for this recipe

types

a list of the types that the recipe is classified under; E.G.: "Appetizers", "Soups"

Example

							
package com.yourpackage;
import com.fatsecret.platform.services.FatsecretService;
import com.fatsecret.platform.model.Recipe;
...
public class YourService {
	public void getFoodItem() {
		String key = "Replace this by your Application Consumer Key";
		String secret = "Replace this by your Consumer Secret";
		FatsecretService service = new FatsecretService(key, secret);
		
		Long id = 319489L;
		Recipe recipe = service.getRecipe(id);
		//This recipe object contains detailed information about the recipe item
	}
}