Le API Google Fit, inclusa l'API REST di Google Fit, verranno ritirate nel 2026. A partire dal 1° maggio 2024, gli sviluppatori non possono registrarsi per utilizzare queste API.
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Puoi aggiungere dati sull'idratazione a Google Fit creando un'origine dati e utilizzando
il tipo di dati com.google.hydration. Ogni punto dati rappresenta il volume,
in litri, consumati da un utente come parte di una singola bevanda. Utilizza un numero in virgola mobile per
e specificare il volume.
Nota: il timestamp indica quando è stata consumata la bevanda. Poiché com.google.hydration è un tipo di dati istantaneo, l'ora di inizio e l'ora di fine devono coincidere.
crea un'origine dati
Android
Utilizza DataSource.Builder per creare una nuova origine dati. Ad esempio, hydrationSource.
Se l'origine dati viene creata correttamente, la risposta è uno stato 200 OK
le API nel tuo codice. Il corpo della risposta contiene una rappresentazione JSON dell'origine dati,
inclusa una proprietà datasource.dataStreamId che puoi utilizzare come dati
per le richieste successive.
Se il punto dati è stato creato correttamente, riceverai un messaggio HTTP 200 OK
codice di stato della risposta. Il corpo della risposta contiene una rappresentazione JSON
il set di dati.
[null,null,["Ultimo aggiornamento 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."]]