Google Health API로 영양 및 수분 섭취량 환경 개발하기

Google Health API는 사용자의 영양 및 수분 섭취를 추적하는 데이터 유형을 제공합니다. 이러한 유형을 사용하면 식사를 기록하고, 음식 데이터베이스에서 음식을 참조하고, 영양소 양을 추적하고, 수분 섭취량을 기록할 수 있습니다.

지원되는 데이터 유형

표: Google Health API 영양 데이터 유형
데이터 유형 사용 가능한
작업
범위
음식
dataType: food
filter parameter: food
기록 유형: 음식
list, get .nutrition.readonly
.nutrition.writeonly
음식 측정 단위
dataType: food-measurement-unit
filter parameter: food_measurement_unit
기록 유형: 음식

호환 기기

list, get .nutrition.readonly
.nutrition.writeonly
수분 섭취 기록
dataType: hydration-log
filter parameter: hydration_log
레코드 유형: 세션
list, get, reconcile, rollup, dailyRollup, create, update, batchDelete .nutrition.readonly
.nutrition.writeonly
영양 기록
dataType: nutrition-log
filter parameter: nutrition_log
레코드 유형: 세션

호환 기기

list, get, reconcile, rollup, dailyRollup, create, update, batchDelete .nutrition.readonly
.nutrition.writeonly

영양 기록

영양 기록은 사용자가 기록한 음식을 나타냅니다. 음식 유형에 따라 영양 기록을 만드는 방법에는 두 가지가 있습니다.

  1. 식별된 음식: 기존 음식 리소스를 참조하도록 food 필드를 설정합니다. nutrients, energy, energyFromFat, totalCarbohydrate, totalFat, foodDisplayName 필드는 참조된 식품에서 자동으로 채워집니다. 이 방법이 권장됩니다.

  2. 익명 음식: foodDisplayName 필드를 수동으로 설정하고 nutrients, energy, energyFromFat, totalCarbohydrate, totalFat 값을 제공합니다. 익명 음식에서 생성된 영양 로그는 생성 후 수정할 수 없습니다.

익명 음식으로 영양 기록 만들기

영양 로그 항목을 만들려면 nutrition-log dataPoints 엔드포인트에 POST 요청을 보냅니다.

요청

POST https://health.googleapis.com/v4/users/me/dataTypes/nutrition-log/dataPoints
Authorization: Bearer access-token
Content-Type: application/json

{
  "nutritionLog": {
    "interval": {
      "startTime": "2026-06-16T18:00:00Z",
      "endTime": "2026-06-16T18:30:00Z"
    },
    "foodDisplayName": "Grilled Chicken Breast",
    "mealType": "DINNER",
    "energy": {
      "kcal": 165
    },
    "totalCarbohydrate": {
      "grams": 0
    },
    "totalFat": {
      "grams": 3.6
    },
    "nutrients": [
      {
        "nutrient": "PROTEIN",
        "quantity": {
          "grams": 31
        }
      },
      {
        "nutrient": "SODIUM",
        "quantity": {
          "grams": 0.074
        }
      }
    ],
    "serving": {
      "amount": 1.0
    }
  }
}

응답

{
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.devicesandservices.health.v4.DataPoint",
    "name": "users/user-id/dataTypes/nutrition-log/dataPoints/data-point-id",
    "dataSource": {
      "recordingMethod": "UNKNOWN",
      "application": {
        "googleWebClientId": "google-web-client-id"
      },
      "platform": "GOOGLE_WEB_API"
    },
    "nutritionLog": {
      "interval": {
        "startTime": "2026-06-16T18:00:00Z",
        "startUtcOffset": "0s",
        "endTime": "2026-06-16T18:30:00Z",
        "endUtcOffset": "0s",
        "civilStartTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 18
          }
        },
        "civilEndTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 18,
            "minutes": 30
          }
        }
      },
      "energy": {
        "kcal": 165
      },
      "totalCarbohydrate": {
        "grams": 0
      },
      "totalFat": {
        "grams": 3.6
      },
      "nutrients": [
        {
          "quantity": {
            "grams": 31
          },
          "nutrient": "PROTEIN"
        },
        {
          "quantity": {
            "grams": 0.074
          },
          "nutrient": "SODIUM"
        }
      ],
      "mealType": "DINNER",
      "serving": {
        "amount": 1
      },
      "foodDisplayName": "Grilled Chicken Breast"
    }
  }
}

식별된 음식으로 영양 로그 만들기

음식 데이터베이스에서 음식 항목을 기록하려면 food 필드를 설정하여 음식 리소스를 참조합니다. API는 영양 필드를 자동으로 채웁니다.

요청

POST https://health.googleapis.com/v4/users/me/dataTypes/nutrition-log/dataPoints
Authorization: Bearer access-token
Content-Type: application/json

{
  "nutritionLog": {
    "interval": {
      "startTime": "2026-06-16T12:00:00Z",
      "endTime": "2026-06-16T12:30:00Z"
    },
    "food": "users/me/dataTypes/food/dataPoints/food-id",
    "mealType": "LUNCH",
    "serving": {
      "amount": 1.0,
      "foodMeasurementUnit": "users/me/dataTypes/food-measurement-unit/dataPoints/food-measurement-unit-id"
    }
  }
}

응답

{
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.devicesandservices.health.v4.DataPoint",
    "name": "users/user-id/dataTypes/nutrition-log/dataPoints/data-point-id",
    "dataSource": {
      "recordingMethod": "UNKNOWN",
      "application": {
        "googleWebClientId": "google-web-client-id"
      },
      "platform": "GOOGLE_WEB_API"
    },
    "nutritionLog": {
      "interval": {
        "startTime": "2026-06-16T12:00:00Z",
        "startUtcOffset": "0s",
        "endTime": "2026-06-16T12:30:00Z",
        "endUtcOffset": "0s",
        "civilStartTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 12
          }
        },
        "civilEndTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 12,
            "minutes": 30
          }
        }
      },
      "energy": {
        "kcal": 95
      },
      "energyFromFat": {
        "kcal": 3
      },
      "totalCarbohydrate": {
        "grams": 25
      },
      "totalFat": {
        "grams": 0.3
      },
      "nutrients": [
        {
          "quantity": {
            "grams": 4.4,
            "userProvidedUnit": "GRAM"
          },
          "nutrient": "DIETARY_FIBER"
        },
        {
          "quantity": {
            "grams": 19,
            "userProvidedUnit": "GRAM"
          },
          "nutrient": "SUGAR"
        },
        {
          "quantity": {
            "grams": 0.5,
            "userProvidedUnit": "GRAM"
          },
          "nutrient": "PROTEIN"
        }
      ],
      "mealType": "LUNCH",
      "serving": {
        "amount": 1,
        "foodMeasurementUnit": "users/me/dataTypes/food-measurement-unit/dataPoints/food-measurement-unit-id"
      },
      "food": "users/user-id/dataTypes/food/dataPoints/food-id",
      "foodDisplayName": "Apple"
    }
  }
}

영양 기록 삭제

하나 이상의 영양 로그 항목을 삭제하려면 삭제할 항목의 리소스 이름과 함께 batchDelete 메서드에 POST 요청을 보냅니다.

요청:

POST https://health.googleapis.com/v4/users/me/dataTypes/nutrition-log/dataPoints:batchDelete
Authorization: Bearer access-token
Content-Type: application/json

{
  "names": [
    "users/me/dataTypes/nutrition-log/dataPoints/data-point-id"
  ]
}

영양 기록 필드

전체 필드 및 설명 목록은 NutritionLog를 참조하세요.

에너지량

킬로칼로리 (kcal)로 측정된 에너지 측정값을 나타냅니다. 자세한 내용은 EnergyQuantity를 참고하세요.

{
  "kcal": 165
}

체중량

체중 측정값을 나타냅니다(단위: 그램). 자세한 내용은 WeightQuantity를 참조하세요.

{
  "grams": 27.3
}

영양소 수량

특정 영양소와 측정된 양을 나타냅니다. 자세한 내용은 NutrientQuantity을 참고하세요.

{
  "nutrient": "PROTEIN",
  "quantity": {
    "grams": 31
  }
}

영양소 값

지원되는 영양소 유형의 전체 목록은 Nutrient을 참고하세요.

서빙

영양 로그 항목의 1회 제공량 정보를 나타냅니다. 자세한 내용은 Serving을 참고하세요.

{
  "amount": 1.5
}

식사 유형 값

지원되는 식사 유형의 전체 목록은 MealType를 참고하세요.

음식

음식은 음식 데이터베이스의 음식 항목을 나타내는 읽기 전용 데이터 유형입니다. list 및 get 작업을 사용하여 사용 가능한 음식을 탐색하고 영양 정보를 가져옵니다.

음식 목록

음식을 나열하려면 food dataPoints 엔드포인트에 GET 요청을 보냅니다.

GET https://health.googleapis.com/v4/users/me/dataTypes/food/dataPoints
Authorization: Bearer access-token
Accept: application/json

음식 측정 단위

음식 측정 단위는 음식 제공량에 사용되는 측정 단위 (예: '컵', '테이블스푼', '조각')를 나타내는 읽기 전용 데이터 유형입니다.

사용 가능한 측정 단위 나열

사용 가능한 측정 단위를 나열하려면 다음 안내를 따르세요.

GET https://health.googleapis.com/v4/users/me/dataTypes/food-measurement-unit/dataPoints
Authorization: Bearer access-token
Accept: application/json

수분 섭취 기록

수분 섭취량 기록은 사용자가 기록한 액체를 나타냅니다. 음식 데이터베이스를 참조하고 영양소 또는 에너지 섭취량을 측정하는 음식과 달리 수분 섭취 항목은 특정 시간 간격 동안 소비된 특정 액체량을 추적합니다.

수분 섭취 기록 만들기

수분 섭취량 로그 항목을 만들려면 hydration-log dataPoints 엔드포인트에 POST 요청을 보냅니다. 모든 부피 수량은 API 형식에서 밀리리터로 변환됩니다.

요청

POST https://health.googleapis.com/v4/users/me/dataTypes/hydration-log/dataPoints
Authorization: Bearer access-token
Content-Type: application/json

{
  "hydrationLog": {
    "interval": {
      "startTime": "2026-06-16T14:00:00Z",
      "endTime": "2026-06-16T14:00:01Z"
    },
    "amountConsumed": {
      "milliliters": 500,
      "userProvidedUnit": "FLUID_OUNCE_US"
    }
  }
}

응답

{
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.devicesandservices.health.v4.DataPoint",
    "name": "users/user-id/dataTypes/hydration-log/dataPoints/data-point-id",
    "dataSource": {
      "recordingMethod": "UNKNOWN",
      "application": {
        "googleWebClientId": "google-web-client-id"
      },
      "platform": "GOOGLE_WEB_API"
    },
    "hydrationLog": {
      "interval": {
        "startTime": "2026-06-16T14:00:00Z",
        "startUtcOffset": "0s",
        "endTime": "2026-06-16T14:00:01Z",
        "endUtcOffset": "0s",
        "civilStartTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 14
          }
        },
        "civilEndTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 14,
            "seconds": 1
          }
        }
      },
      "amountConsumed": {
        "milliliters": 500,
        "userProvidedUnit": "FLUID_OUNCE_US"
      }
    }
  }
}

수분 섭취 기록 업데이트

수분 섭취량 로그 항목을 업데이트하려면 데이터 포인트의 ID와 함께 PATCH 요청을 hydration-log dataPoints 엔드포인트로 전송합니다.

요청

PATCH https://health.googleapis.com/v4/users/me/dataTypes/hydration-log/dataPoints/data-point-id
Authorization: Bearer access-token
Content-Type: application/json

{
  "hydrationLog": {
    "interval": {
      "startTime": "2026-06-16T10:00:00Z",
      "endTime": "2026-06-16T10:00:01Z"
    },
    "amountConsumed": {
      "milliliters": 500
    }
  }
}

응답

{
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.devicesandservices.health.v4.DataPoint",
    "name": "users/user-id/dataTypes/hydration-log/dataPoints/data-point-id",
    "dataSource": {
      "recordingMethod": "UNKNOWN",
      "application": {
        "googleWebClientId": "google-web-client-id"
      },
      "platform": "GOOGLE_WEB_API"
    },
    "hydrationLog": {
      "interval": {
        "startTime": "2026-06-16T10:00:00Z",
        "startUtcOffset": "0s",
        "endTime": "2026-06-16T10:00:01Z",
        "endUtcOffset": "0s",
        "civilStartTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 10
          }
        },
        "civilEndTime": {
          "date": {
            "year": 2026,
            "month": 6,
            "day": 16
          },
          "time": {
            "hours": 10,
            "seconds": 1
          }
        }
      },
      "amountConsumed": {
        "milliliters": 500
      }
    }
  }
}

수분 섭취 기록 삭제

수분 섭취량 로그 항목을 하나 이상 삭제하려면 batchDelete 메서드에 POST 요청을 보냅니다.

요청

POST https://health.googleapis.com/v4/users/me/dataTypes/hydration-log/dataPoints:batchDelete
Authorization: Bearer access-token
Content-Type: application/json

{
  "names": [
    "users/me/dataTypes/hydration-log/dataPoints/data-point-id"
  ]
}

응답

{
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.devicesandservices.health.v4.BatchDeleteDataPointsResponse",
    "dataPoints": [
      {
        "name": "users/user-id/dataTypes/hydration-log/dataPoints/data-point-id",
        "dataSource": {
          "recordingMethod": "UNKNOWN",
          "application": {
            "googleWebClientId": "google-web-client-id"
          },
          "platform": "GOOGLE_WEB_API"
        },
        "hydrationLog": {
          "interval": {
            "startTime": "2026-06-16T14:00:00Z",
            "startUtcOffset": "0s",
            "endTime": "2026-06-16T14:00:01Z",
            "endUtcOffset": "0s",
            "civilStartTime": {
              "date": {
                "year": 2026,
                "month": 6,
                "day": 16
              },
              "time": {
                "hours": 14
              }
            },
            "civilEndTime": {
              "date": {
                "year": 2026,
                "month": 6,
                "day": 16
              },
              "time": {
                "hours": 14,
                "seconds": 1
              }
            }
          },
          "amountConsumed": {
            "milliliters": 500,
            "userProvidedUnit": "FLUID_OUNCE_US"
          }
        }
      }
    ]
  }
}

수분 섭취 기록 필드

전체 필드 및 설명 목록은 HydrationLog를 참조하세요.

볼륨 수량

부피 측정값을 나타냅니다(밀리리터 단위). 자세한 내용은 VolumeQuantity를 참조하세요.

{
  "milliliters": 250,
  "userProvidedUnit": "MILLILITER"
}

부피 단위 값

지원되는 볼륨 단위의 전체 목록은 VolumeUnit를 참조하세요. 일반적인 값에는 MILLILITER, LITER, CUP_US, FLUID_OUNCE_US가 포함됩니다.

가이드라인

  • 가능한 경우 식별된 음식을 사용합니다. API는 영양 필드를 자동으로 채워 오류를 줄이고 식품 데이터베이스와의 일관성을 보장합니다.
  • 익명 음식으로 생성된 영양 기록은 생성 후 업데이트할 수 없습니다. 익명 음식 기록을 수정해야 하는 경우 삭제하고 새로 만드세요.
  • 익명 음식 영양 로그와 달리 수분 섭취량 로그 항목은 완전히 변경 가능하며 생성 후 PATCH 요청을 사용하여 업데이트할 수 있습니다.
  • nutrients 배열의 모든 영양소 수량은 그램을 측정 단위로 사용합니다.
  • energy 및 energyFromFat 필드는 킬로칼로리 (kcal)를 측정 단위로 사용합니다.
  • API는 모든 수분 섭취량을 밀리리터 단위로 변환하고 저장합니다. VolumeQuantity의 선택적 userProvidedUnit 필드는 클라이언트 측 사용자 대상 표시에만 사용됩니다.
  • 개별 hydration-log 데이터 포인트에 대한 직접 HTTP DELETE 요청은 404 Not Found를 반환합니다. batchDelete 메서드를 사용하여 이러한 리소스 항목을 삭제합니다.
  • 수분 섭취량 로그는 startTime 및 endTime가 액체를 섭취한 기간을 나타내는 짧은 간격을 사용합니다.