Las APIs de Google Fit, incluida la API de REST de Google Fit, dejarán de estar disponibles en 2026. A partir del 1 de mayo de 2024, los desarrolladores no podrán registrarse para usar estas APIs.
Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Para agregar datos de hidratación a Google Fit, crea una fuente de datos y usa
el tipo de datos com.google.hydration. Cada dato representa el volumen,
en litros, consumidas por un usuario como parte de una sola bebida. Usa un número de punto flotante para
para especificar el volumen.
Nota: La marca de tiempo indica cuándo se consumió la bebida. Como com.google.hydration es un tipo de datos instantáneo, la hora de inicio y finalización deben ser la misma.
Cree una fuente de datos
Android
Usa DataSource.Builder para crear una nueva fuente de datos. Por ejemplo, hydrationSource
Si la fuente de datos se creó correctamente, la respuesta tendrá un estado 200 OK.
código. El cuerpo de la respuesta contiene una representación JSON de la fuente de datos.
incluida una propiedad datasource.dataStreamId que puedas usar como datos
el ID de origen para solicitudes posteriores.
Si tu dato se creó correctamente, obtendrás un código HTTP 200 OK.
el código de estado de respuesta. El cuerpo de la respuesta contiene una representación JSON de
el conjunto de datos.
[null,null,["Última actualización: 2025-08-31 (UTC)"],[[["\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."]]