Các API của Google Fit, bao gồm cả API Google Fit REST, sẽ ngừng hoạt động vào năm 2026. Kể từ ngày 1 tháng 5 năm 2024, nhà phát triển không thể đăng ký sử dụng các API này.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Ứng dụng của bạn có thể ghi dữ liệu đường huyết bằng cách ghi vào
Loại dữ liệu com.google.blood_glucose. Trong loại dữ liệu này, mỗi điểm dữ liệu biểu thị một
chỉ số đường huyết. Điểm dữ liệu chứa các trường về đường huyết
sự tập trung, mối quan hệ tạm thời với bữa ăn và giấc ngủ, cũng như nguồn gốc của
mẫu được đo. Tất cả các trường, ngoại trừ nồng độ đường huyết
là không bắt buộc.
Nồng độ đường huyết được đo bằng mmol/L (1 mmol/L là
tương đương 18 mg/dL).
Nếu được chỉ định, mối quan hệ tạm thời với bữa ăn phải có một trong các giá trị được liệt kê
trong FIELD_TEMPORAL_RELATION_TO_MEAL.
Loại bữa ăn phải có một trong các giá trị nêu trong FIELD_MEAL_TYPE.
Nếu bạn không xác định được loại bữa ăn, hãy sử dụng MEAL_TYPE_UNKNOWN.
Nếu được chỉ định, mối quan hệ tạm thời với giấc ngủ phải có một trong các giá trị được liệt kê
trong FIELD_TEMPORAL_RELATION_TO_SLEEP.
Nếu nguồn dữ liệu được tạo thành công, thì phản hồi sẽ có trạng thái 200 OK
. Nội dung phản hồi chứa bản trình bày JSON của nguồn dữ liệu,
bao gồm thuộc tính datasource.dataStreamId mà bạn có thể sử dụng làm dữ liệu
mã nguồn cho các yêu cầu tiếp theo.
Để cho rõ ràng, phần nội dung JSON hiển thị bên dưới được chú thích bằng nhận xét để hiển thị
việc sử dụng hằng số trường sức khoẻ.
Mặc dù API Fit hiện sẽ bỏ nhận xét, nhưng
bạn nên xoá các thẻ này khỏi mã của mình, vì JSON không
bình luận hỗ trợ chính thức.
Nếu dữ liệu đường huyết được thêm thành công, phản hồi sẽ là 200 OK
mã trạng thái. Nội dung phản hồi chứa tệp JSON đại diện cho máu
glucose đã được thêm vào.
[null,null,["Cập nhật lần gần đây nhất: 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."]]