Interfejsy Google Fit API, w tym interfejs Google Fit API typu REST, zostaną wycofane w 2026 roku. Od 1 maja 2024 r. deweloperzy nie mogą rejestrować się w celu korzystania z tych interfejsów API.
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Aplikacja może zapisywać dane dotyczące glukozy we krwi, zapisując w
com.google.blood_glucose. W tym typie danych każdy punkt danych reprezentuje jedną chwilową
odczyt glukozy we krwi. Punkt danych zawiera pola na poziom glukozy we krwi
koncentrację, czasowe związki z posiłkami i snem oraz źródło
każdej z próbek,
która została zmierzona. Wszystkie pola oprócz stężenia glukozy we krwi
są opcjonalne.
Stężenie glukozy we krwi jest mierzone w mmol/L (1 mmol/L to
co odpowiada 18 mg/dl).
Jeśli zostanie określony, czasowy stosunek do posiłku musi mieć jedną z wymienionych wartości
w sekcji FIELD_TEMPORAL_RELATION_TO_MEAL.
Typ posiłku musi mieć jedną z wartości wymienionych w polu FIELD_MEAL_TYPE.
Jeśli nie znasz rodzaju posiłku, użyj MEAL_TYPE_UNKNOWN.
Jeśli zostanie określony, czasowy stosunek do snu musi mieć jedną z wymienionych wartości
w sekcji FIELD_TEMPORAL_RELATION_TO_SLEEP.
Jeśli źródło danych zostało utworzone, odpowiedź ma stan 200 OK
w kodzie. Treść odpowiedzi zawiera reprezentację źródła danych w formacie JSON,
włącznie z usługą datasource.dataStreamId, której możesz używać jako danych,
identyfikatora źródła na potrzeby kolejnych żądań.
Aby ułatwić zrozumienie, treść JSON widoczna poniżej jest opatrzona komentarzami. Pozwala ona
dzięki stałej porcji zdrowia.
Choć interfejs Fit API obecnie pomija komentarze,
zdecydowanie zalecamy usunięcie ich z kodu, ponieważ JSON nie
oficjalnie obsługuje komentarze.
Jeśli dane o stężeniu glukozy we krwi zostaną dodane, odpowiedź będzie miała postać 200 OK
kodu stanu. Treść odpowiedzi zawiera reprezentację krwi w formacie JSON
glukozy, które zostały dodane.
[null,null,["Ostatnia aktualizacja: 2025-08-31 UTC."],[[["\u003cp\u003eYour app can record single, instantaneous blood glucose readings using the \u003ccode\u003ecom.google.blood_glucose\u003c/code\u003e data type, including optional fields for meal, sleep, and specimen source information.\u003c/p\u003e\n"],["\u003cp\u003eBlood glucose concentration is measured in mmol/L, and all other fields have specific allowed values as defined in the documentation.\u003c/p\u003e\n"],["\u003cp\u003eYou need to create a data source of type \u003ccode\u003ecom.google.blood_glucose\u003c/code\u003e before you can start writing blood glucose data.\u003c/p\u003e\n"],["\u003cp\u003eThe History API is used to add blood glucose data points to the created data source, with each point containing a timestamp and the blood glucose level, along with optional fields.\u003c/p\u003e\n"],["\u003cp\u003eGoogle Fit enforces restrictions on read/write access to health data types like blood glucose due to their sensitive nature.\u003c/p\u003e\n"]]],[],null,["# Write Blood Glucose Data\n\nYour app can record blood glucose data by writing to the\n[`com.google.blood_glucose`](/android/reference/com/google/android/gms/fitness/data/HealthDataTypes#TYPE_BLOOD_GLUCOSE) data type. In this data type, each data point represents a single instantaneous\nblood glucose reading. The data point contains fields for the blood glucose\nconcentration, temporal relationships to meals and sleep, and the source of the\nspecimen which was measured. All fields except for blood glucose concentration\nare optional.\n| **Note:** Because health data is potentially sensitive, Google Fit [restricts read/write\n| access to health data types](/fit/datatypes/restricted).\n\n- The blood glucose concentration is measured in *mmol/L* (1 mmol/L is equivalent to 18 mg/dL).\n- If specified, temporal relation to meal must have one of the values listed in [`FIELD_TEMPORAL_RELATION_TO_MEAL`](/android/reference/com/google/android/gms/fitness/data/HealthFields#FIELD_TEMPORAL_RELATION_TO_MEAL).\n- Meal type must have one of the values listed in [`FIELD_MEAL_TYPE`](/android/reference/com/google/android/gms/fitness/data/Field#FIELD_MEAL_TYPE). If the meal type is not known, use [`MEAL_TYPE_UNKNOWN`](/android/reference/com/google/android/gms/fitness/data/Field#MEAL_TYPE_UNKNOWN).\n- If specified, temporal relation to sleep must have one of the values listed in [`FIELD_TEMPORAL_RELATION_TO_SLEEP`](/android/reference/com/google/android/gms/fitness/data/HealthFields#FIELD_TEMPORAL_RELATION_TO_SLEEP).\n- If specified, blood glucose specimen source must have one of the values listed in [`FIELD_BLOOD_GLUCOSE_SPECIMEN_SOURCE`](/android/reference/com/google/android/gms/fitness/data/HealthFields#FIELD_BLOOD_GLUCOSE_SPECIMEN_SOURCE).\n\nCreate a data source\n--------------------\n\n### Android\n\nTo write a blood glucose data point, create a new [`DataSource`](/android/reference/com/google/android/gms/fitness/data/DataSource)\nof [`TYPE_BLOOD_GLUCOSE`](/android/reference/com/google/android/gms/fitness/data/HealthDataTypes#TYPE_BLOOD_GLUCOSE),\nas shown in the following example: \n\n val bloodGlucoseSource = DataSource.Builder()\n .setDataType(TYPE_BLOOD_GLUCOSE)\n // ...\n .build()\n\n### REST\n\nTo write a blood glucose data point, create a new data source.\n\n**HTTP method** \n\n POST\n\n**Request URL** \n\n```html\nhttps://www.googleapis.com/fitness/v1/users/me/dataSources\n```\n\n**Request body** \n\n {\n \"dataStreamName\": \"BloodGlucose\",\n \"type\": \"raw\",\n \"application\": {\n \"detailsUrl\": \"http://example.com\",\n \"name\": \"My Example App\",\n \"version\": \"1\"\n },\n \"dataType\": {\n \"name\": \"com.google.blood_glucose\"\n }\n }\n\n**Response**\n\nIf the data source is created successfully, the response is a `200 OK` status\ncode. The response body contains a JSON representation of the data source,\nincluding a `datasource.dataStreamId` property that you can use as the data\nsource ID for subsequent requests.\n\n**CURL command** \n\n```\n$ curl --header \"Authorization: Bearer ya29.yourtokenvalue --request POST \\\n --header \"Content-Type: application/json;encoding=utf-8\" --data @blood-glucose-ds.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataSources\n```\n\nAdding data\n-----------\n\n### Android\n\nTo add data to the source created above, create a data point for this data\nsource, which can be inserted using the History API: \n\n val bloodGlucose = DataPoint.builder(bloodGlucoseSource)\n .setTimestamp(timestamp, TimeUnit.MILLISECONDS)\n .setField(FIELD_BLOOD_GLUCOSE_LEVEL, 5.0f) // 90 mg/dL\n .setField(FIELD_TEMPORAL_RELATION_TO_MEAL, FIELD_TEMPORAL_RELATION_TO_MEAL_BEFORE_MEAL)\n .setField(FIELD_MEAL_TYPE, MEAL_TYPE_BREAKFAST)\n .setField(FIELD_TEMPORAL_RELATION_TO_SLEEP, TEMPORAL_RELATION_TO_SLEEP_ON_WAKING)\n .setField(FIELD_BLOOD_GLUCOSE_SPECIMEN_SOURCE, BLOOD_GLUCOSE_SPECIMEN_SOURCE_CAPILLARY_BLOOD)\n .build()\n\n### REST\n\nThis example demonstrates adding blood glucose data using the\n[data source created above](#create_a_data_source).\n\n**HTTP method** \n\n PATCH\n\n**Request URL** \n\n```html\nhttps://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000\n```\n\n**Request body**\n\nFor clarity the JSON body shown below is annotated with comments, to show\nthe use of health field constants.\nAlthough the Fit API will currently drop comments, it is\n**highly recommended you remove these from your code**, as JSON does not\nofficially support comments. \n\n```restructuredtext\n{\n \"minStartTimeNs\": 1574159699023000000,\n \"maxEndTimeNs\": 1574159699023000000,\n \"dataSourceId\": \"datasource.dataStreamId\",\n \"point\": [\n {\n \"startTimeNanos\": 1574159699023000000,\n \"endTimeNanos\": 1574159699023000000,\n \"dataTypeName\": \"com.google.blood_glucose\",\n \"value\": [\n {\n // Blood glucose level, 90 mg/dL\n \"fpVal\": 5.0\n },\n {\n // FIELD_TEMPORAL_RELATION_TO_MEAL_BEFORE_MEAL\n \"intVal\": 3\n },\n {\n // MEAL_TYPE_BREAKFAST\n \"intVal\": 1\n },\n {\n // TEMPORAL_RELATION_TO_SLEEP_ON_WAKING\n \"intVal\": 3\n },\n {\n // BLOOD_GLUCOSE_SPECIMEN_SOURCE_CAPILLARY_BLOOD\n \"intVal\": 2\n }\n ]\n }\n ]\n}\n```\n\n**Response**\n\nIf the blood glucose data is added successfully, the response is a `200 OK`\nstatus code. The response body contains a JSON representation of the blood\nglucosedata that has been added.\n\n**CURL command** \n\n```\n$ curl --header \"Authorization: Bearer ya29.yourtokenvalue --request PATCH \\\n --header \"Content-Type: application/json;encoding=utf-8\" --data @blood-glucose-data.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataSources/datasource.dataStreamId/datasets/1574159699023000000-1574159699023000000\n```\n| **Note:** Use --request PATCH (not --request POST) in your CURL command when adding data."]]