سيتم إيقاف واجهات برمجة تطبيقات Google Fit نهائيًا في عام 2026، بما في ذلك واجهة برمجة التطبيقات Google Fit REST API. اعتبارًا من 1 أيار (مايو) 2024، لن يتمكّن المطوّرون من الاشتراك لاستخدام واجهات برمجة التطبيقات هذه.
للحصول على تعليمات حول واجهة برمجة التطبيقات أو المنصة التي تريد نقل البيانات إليها، يُرجى الانتقال إلى دليل نقل البيانات في Health Connect. للاطّلاع على مقارنة بين Health Connect وGoogle Fit API وFitbit Web API، يُرجى الانتقال إلى دليل مقارنة Health Connect.
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
ويمكنك إضافة بيانات استهلاك السوائل إلى Google Fit من خلال إنشاء مصدر بيانات واستخدام
نوع بيانات com.google.hydration. تمثل كل نقطة بيانات الحجم،
باللتر، الذي يستهلكه المستخدم كجزء من مشروب واحد استخدام عدد عائم من أجل
لتحديد مستوى الصوت.
ملاحظة: يشير الطابع الزمني إلى وقت استهلاك المشروب. بما أنّ com.google.hydration هو نوع بيانات لحظي، يجب أن يكون وقت البدء وتاريخ الانتهاء متطابقَين.
إنشاء مصدر بيانات
Android
استخدِم DataSource.Builder لإنشاء مصدر بيانات جديد. مثلاً: hydrationSource
إذا تم إنشاء مصدر البيانات بنجاح، تكون حالة الردّ 200 OK.
الرمز. يحتوي نص الاستجابة على تمثيل JSON لمصدر البيانات،
بما في ذلك السمة datasource.dataStreamId التي يمكنك استخدامها للبيانات
معرّف المصدر للطلبات اللاحقة.
تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-31 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eYou can add hydration data to Google Fit by creating a data source and using the \u003ccode\u003ecom.google.hydration\u003c/code\u003e data type.\u003c/p\u003e\n"],["\u003cp\u003eEach data point represents the volume of a single drink consumed by a user, specified in liters using a float value, with the timestamp indicating the consumption time.\u003c/p\u003e\n"],["\u003cp\u003eData sources can be created using the \u003ccode\u003eDataSource.Builder\u003c/code\u003e in Android or by calling the REST API with a specific request body.\u003c/p\u003e\n"],["\u003cp\u003eHydration data can be added using \u003ccode\u003eDataPoint.builder\u003c/code\u003e in Android or through the REST API with a PATCH request containing the data point details.\u003c/p\u003e\n"]]],[],null,["# Add Hydration Data\n\nYou can add hydration data to Google Fit by [creating a data source](#creating_a_data_source) and using\nthe [`com.google.hydration`](/android/reference/com/google/android/gms/fitness/data/DataType#TYPE_HYDRATION) data type. Each data point represents the volume,\nin liters, consumed by a user as part of a single drink. Use a float to\nspecify volume.\nNote: The timestamp indicates when the drink was consumed. Because [`com.google.hydration`](/android/reference/com/google/android/gms/fitness/data/DataType#TYPE_HYDRATION) is an instantaneous data type, the start and end time should be the same.\n\nCreating a data source\n----------------------\n\n### Android\n\nUse `DataSource.Builder` to create a new data source. For example, `hydrationSource`. \n\n val hydrationSource = DataSource.Builder()\n .setDataType(DataType.TYPE_HYDRATION)\n .setStreamName(\"hydrationSource\")\n // ... \n .build()\n\n### REST\n\nCall the REST API to create a new data source. For example, `HydrationSource`.\n\n**HTTP method** \n\n POST\n\n**Request URL** \n\n https://www.googleapis.com/fitness/v1/users/me/dataSources\n\n**Request body** \n\n {\n \"dataStreamName\": \"HydrationSource\",\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.hydration\",\n \"field\": [\n {\n \"name\": \"volume\",\n \"format\": \"floatPoint\",\n \"optional\": false\n }\n ]\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 $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" --request POST \\\n --header \"Content-Type: application/json;encoding=utf-8\" --data @hydration-ds.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataSources\n\nAdding Hydration Data\n---------------------\n\n### Android\n\nThis example shows you how to create a new data point, and add hydration\ndata for a 0.3 liter drink of water, using your data source. \n\n val hydration = DataPoint.builder(hydrationSource)\n .setTimestamp(timestamp, TimeUnit.MILLISECONDS)\n .setField(FIELD_VOLUME, 0.3f)\n .build()\n\n### REST\n\nThis example shows you how to add hydration data using your data\nsource.\n\n**HTTP method** \n\n PATCH\n\n**Request URL** \n\n https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.hydration:407408718192:HydrationSource/datasets/1275753581000000000-1275753581000000000\n\n**Request body** \n\n {\n \"minStartTimeNs\": 1275753581000000000,\n \"maxEndTimeNs\": 1275753581000000000,\n \"dataSourceId\": \"raw:com.google.hydration:407408718192:HydrationSource\",\n \"point\": [\n {\n \"startTimeNanos\": 1275753581000000000,\n \"endTimeNanos\": 1275753581000000000,\n \"dataTypeName\": \"com.google.hydration\",\n \"value\": [\n {\n \"fpVal\": 0.3\n }\n ]\n }\n ]\n }\n\n**Response**\n\nIf your data point was created successfully, you'll get a [`200 OK`](https://httpstatuses.com/200) HTTP\nresponse status code. The response body contains a JSON representation of\nthe data set.\n\n**CURL command** \n\n $ curl --header \"Authorization: Bearer ya29.yourtokenvalue\" --request PATCH \\\n --header \"Content-Type: application/json;encoding=utf-8\" --data @hydration-data.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.hydration:407408718192:HydrationSource/datasets/1275753581000000000-1275753581000000000\n\n| **Note:** Use `--request PATCH` (not `--request POST`) in your CURL command when adding data."]]