Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with getting Foods using latest version (1.0.25) of Fitbit4J

When I'm trying to get foods from Fitbit using method

com.fitbit.api.client.service.FitbitAPIClientServicegetClient().getFoods(localUser, FitbitUser.CURRENT_AUTHORIZED_USER, date)

I received such exception: 

com.fitbit.api.FitbitApiException: JSONObject["nutritionalValues"] not found. 

at com.fitbit.api.common.model.foods.constructFoods(Food.java:45)

...

After debugging I found that api.fitbit.com services didn't return in JSON response com.fitbit.api.common.model.foods.FoodLog.nutritionalValues - mandatory field of FoodLog model.

 

 

 

Best Answer
0 Votes
2 REPLIES 2

I found that  some foods are returning with nutritionalValues, but most of them are returning without this mandatory field. For example:

{
  "foods": [
    {
      "isFavorite": false,
      "logDate": "2014-11-21",
      "logId": 1482270469,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 1,
        "brand": "Egg Harbor Cafe",
        "calories": 162,
        "foodId": 14000042,
        "locale": "en_US",
        "mealTypeId": 2,
        "name": "Feta",
        "unit": {
          "id": 304,
          "name": "serving",
          "plural": "servings"
        },
        "units": [
          304
        ]
      }
    },
    {
      "isFavorite": false,
      "logDate": "2014-11-21",
      "logId": 1482322989,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 1,
        "brand": "Zenner's",
        "calories": 270,
        "foodId": 14595294,
        "locale": "en_US",
        "mealTypeId": 2,
        "name": "Bratwurst",
        "unit": {
          "id": 188,
          "name": "link",
          "plural": "links"
        },
        "units": [
          188
        ]
      }
    },
    {
      "isFavorite": false,
      "logDate": "2014-11-21",
      "logId": 1482322372,
      "loggedFood": {
        "accessLevel": "PUBLIC",
        "amount": 1,
        "brand": "MLO",
        "calories": 18,
        "foodId": 3301,
        "locale": "en_US",
        "mealTypeId": 3,
        "name": "Protein Powder, Milk & Egg",
        "unit": {
          "id": 364,
          "name": "tsp",
          "plural": "tsp"
        },
        "units": [
          349,
          364
        ]
      },
      "nutritionalValues": {
        "calories": 18,
        "carbs": 0.5,
        "fat": 0.5,
        "fiber": 0,
        "protein": 3.5,
        "sodium": 21
      }
    }
  ],
  "summary": {
    "calories": 450,
    "carbs": 1.5,
    "fat": 36.5,
    "fiber": 0,
    "protein": 27.5,
    "sodium": 1310,
    "water": 0
  }
}

Best Answer
0 Votes