Stay organized with collections
Save and categorize content based on your preferences.
Android
Your app can get a list of food items eaten within a specified time frame by
creating a data read request and querying for DataType.TYPE_NUTRITION, as
shown in the following example:
Retrieving a list of food items eaten, via the REST API is a three stage
process:
Retrieve a list of data sources available for the com.google.nutrition
data type. Alternatively, if the data source details are already known,
these can be used directly in the next step.
Obtain a list of food eaten from each data source in turn.
(If there is more than one data source) combine the lists of food
items within the client application.
Retrieving a list of food data sources
As only the datasource.dataStreamId is required from each data source,
a field mask can be used, as shown here, to limit the response to just this
property.
[null,null,["Last updated 2025-08-28 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```"]]