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.
Android
Ihre App kann eine Liste der Lebensmittel abrufen, die Sie innerhalb eines bestimmten Zeitraums gegessen haben, indem sie
eine Datenleseanfrage erstellen und DataType.TYPE_NUTRITION abfragen, wie
Beispiel:
Der Abruf einer Liste der verzehrten Lebensmittel über die REST API erfolgt in drei Schritten.
Prozess:
Liste der für com.google.nutrition verfügbaren Datenquellen abrufen
Datentyp. Wenn die Details der Datenquelle bereits bekannt sind,
diese können im nächsten Schritt direkt verwendet werden.
Sie können eine Liste der Lebensmittel abrufen, die der Reihe nach aus den einzelnen Datenquellen gegessen werden.
(Falls mehrere Datenquellen vorhanden sind) kombinieren Sie die Listen mit Lebensmitteln.
Elemente innerhalb der Client-Anwendung.
Liste von Datenquellen zu Lebensmitteln abrufen
Da für jede Datenquelle nur das Feld datasource.dataStreamId erforderlich ist,
wie hier gezeigt, kann eine Feldmaske verwendet werden, um die Antwort auf diese
Property.
Wenn der Vorgang erfolgreich war, wird der Statuscode 200 OK zurückgegeben. Der Antworttext
enthält eine JSON-Liste, wobei jedes Element in der Liste einer Datenquelle entspricht.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-31 (UTC)."],[[["\u003cp\u003eAccess food item data within a specified timeframe using \u003ccode\u003eDataType.TYPE_NUTRITION\u003c/code\u003e for Android apps.\u003c/p\u003e\n"],["\u003cp\u003eRetrieve food item data via REST API using a 3-step process: identifying data sources, obtaining food data from each source, and consolidating the data.\u003c/p\u003e\n"],["\u003cp\u003eA data source identifier (\u003ccode\u003edataStreamId\u003c/code\u003e) is crucial for fetching data, which can be obtained using a dedicated API request with field masking.\u003c/p\u003e\n"],["\u003cp\u003eFood item data is accessed via specific REST endpoints by specifying \u003ccode\u003edataStreamId\u003c/code\u003e and the desired timeframe (\u003ccode\u003edatasetId\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eCustomize the data retrieval by using field masks to include or exclude specific data points like timestamps and nutrient values.\u003c/p\u003e\n"]]],[],null,["# Read food items eaten\n\n### Android\n\nYour app can get a list of food items eaten within a specified time frame by\ncreating a data read request and querying for `DataType.TYPE_NUTRITION`, as\nshown in the following example: \n\n val readRequest = DataReadRequest.Builder()\n .read(DataType.TYPE_NUTRITION)\n .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)\n .build()\n\nFor more information about reading data, see [Work with the Fitness History](/fit/android/history).\n\n### REST\n\nRetrieving a list of food items eaten, via the REST API is a three stage\nprocess:\n\n1. Retrieve a list of data sources available for the `com.google.nutrition` data type. *Alternatively, if the data source details are already known,\n these can be used directly in the next step.*\n2. Obtain a list of food eaten from each data source in turn.\n3. (*If there is more than one data source*) combine the lists of food items within the client application.\n\n### Retrieving a list of food data sources\n\nAs only the `datasource.dataStreamId` is required from each [data source](https://developers.google.com/fit/rest/v1/reference/users/dataSources#resource),\na field mask can be used, as shown here, to limit the response to just this\nproperty.\n\n**HTTP method** \n\n GET\n\n**Request URL** \n\n```html\nhttps://www.googleapis.com/fitness/v1/users/me/dataSources?dataTypeName=com.google.nutrition&fields=dataSource(dataStreamId)\n```\n\n**Response**\n\nIf successful, the response is a `200 OK` status code. The response body\ncontains a JSON list, each item in the list corresponding to a data source.\n\nFor example: \n\n {\n \"dataSource\": [\n {\n \"dataStreamId\": \"raw:com.google.nutrition:com.example.nutritionSource1:\"\n },\n {\n \"dataStreamId\": \"raw:com.google.nutrition:com.example.nutritionSource2:\"\n }\n ]\n }\n\n**CURL command** \n\n```html\n$ curl \\\n 'https://www.googleapis.com/fitness/v1/users/me/dataSources?dataTypeName=com.google.nutrition&fields=dataSource(dataStreamId)' \\\n --header 'Authorization: Bearer ya29.yourtokenvalue' \\\n --header 'Accept: application/json' \\\n --compressed\n```\n\n### Obtaining a list of food eaten from a data source\n\nUse the `dataSource.dataStreamId` from each of the sources in step 1, in\nturn, to retrieve the list(s) of food eaten.\n\nThe `datasetId` is start and end of the required time period, in nanoseconds\nas defined in the [data set resource](https://developers.google.com/fit/rest/v1/reference/users/dataSources/datasets/get#parameters).\n\nFor example, `1546300800000000000-1546387200000000000` represents the\n`datasetId` for *01 Jan 2019 00:00:00 UTC* to *02 Jan 2019 00:00:00*.\n| **Note:** You can use a field mask to only get relevant values in the response. This example uses the `point/value/stringVal` field mask to only get the names of the food items eaten (shown in `stringVal`). It excludes the other default fields in the data set resource for the `com.google.nutrition` data points like `nutrients`, `meal_type` and `food_item`. You can edit the field mask to add or remove properties. For example, `point(startTimeNanos,value/stringVal)` would include a timestamp against each food item.\n\n**HTTP method** \n\n GET\n\n**Request URL** \n\n```html\nhttps://www.googleapis.com/fitness/v1/users/me/dataSources/dataSource.dataStreamId/datasets/1546300800000000000-1546387200000000000?fields=point%2Fvalue%2FstringVal\n```\n\n**Response** \n\n {\n \"point\": [\n {\n \"value\": [\n {},\n {},\n {\n \"stringVal\": \"apple\"\n }\n ]\n },\n {\n \"value\": [\n {},\n {},\n {\n \"stringVal\": \"banana\"\n }\n ]\n },\n {\n \"value\": [\n {},\n {},\n {\n \"stringVal\": \"carrot\"\n }\n ]\n }\n ]\n }\n\n**CURL command** \n\n```html\n$ curl \\\n 'https://www.googleapis.com/fitness/v1/users/me/dataSources/dataSource.dataStreamId/datasets/157059699023000000-1575159699023999000?fields=point%2Fvalue%2FstringVal' \\\n --header 'Authorization: Bearer ya29.yourtokenvalue' \\\n --header 'Accept: application/json' \\\n --compressed\n```"]]