Die Google Fit APIs, einschließlich der Google Fit REST API, werden 2026 eingestellt. Ab dem 1. Mai 2024 können sich Entwickler nicht mehr für die Verwendung dieser APIs registrieren.
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Sie können Daten zur Flüssigkeitszufuhr in Google Fit hinzufügen, indem Sie eine Datenquelle erstellen und
com.google.hydration-Datentyp. Jeder Datenpunkt steht für das Volumen,
in Litern, die der Nutzer als Teil eines einzelnen Getränks konsumiert. Verwenden Sie eine Gleitkommazahl,
Lautstärke angeben.
Hinweis: Der Zeitstempel gibt an, wann das Getränk getrunken wurde. Da es sich bei com.google.hydration um einen sofortigen Datentyp handelt, sollten Start- und Endzeit identisch sein.
Datenquelle erstellen
Android
Verwenden Sie DataSource.Builder, um eine neue Datenquelle zu erstellen. Beispiel: hydrationSource.
Wenn die Datenquelle erstellt wurde, hat die Antwort den Status 200 OK
Code. Der Antworttext enthält eine JSON-Darstellung der Datenquelle.
einschließlich einer datasource.dataStreamId-Eigenschaft, die Sie als Daten
Quellen-ID für nachfolgende Anfragen.
In diesem Beispiel wird gezeigt, wie Sie einen neuen Datenpunkt erstellen und die Flüssigkeitszufuhr hinzufügen.
für ein 0, 3-Liter-Getränk Wasser mit Ihrer Datenquelle.
Wenn der Datenpunkt erstellt wurde, erhalten Sie eine HTTP-Meldung 200 OK
Statuscode der Antwort. Der Antworttext enthält eine JSON-Darstellung von
des Datasets.
[null,null,["Zuletzt aktualisiert: 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."]]