讀取每日營養匯總資料
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本節示範從特定
做為資料來源回應會包含值區清單 (每 24 小時一個清單)
每個資料集都含有單一資料集和資料點
營養資料類型。如果特定時間沒有營養價值
句號內,但沒有資料集。如果記錄多個meal_type
,
值將設為 UNKNOWN
。
REST
您的應用程式可以透過下列方式讀取使用者的每日營養資料匯總資料:
發出 POST
要求並查詢指定的資料來源。您必須
為每個資料來源分別查詢。
HTTP 方法
POST
要求網址
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
要求主體
{
"aggregateBy": [{
"dataSourceId":
"raw:com.google.nutrition:407408718192:MyDataSource"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1471244400000,
"endTimeMillis": 1471259040000
}
回應
如果成功建立資料來源,回應會是 200 OK
狀態碼。回應主體包含資料的 JSON 表示法
來源,包括可用於 datasource.dataStreamId
屬性
後續要求的資料來源 ID
CURL 指令
$ curl --header "Authorization: Bearer ya29.yourtokenvalue --request POST \
--header "Content-Type: application/json;encoding=utf-8" --data @aggregate.json \
https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eThis documentation explains how to access daily aggregate nutrition data from a specific data source.\u003c/p\u003e\n"],["\u003cp\u003eThe data is organized in 24-hour buckets, with each bucket containing a single dataset and datapoint for all recorded nutrition data types.\u003c/p\u003e\n"],["\u003cp\u003eAndroid and REST API examples are provided for retrieving this data.\u003c/p\u003e\n"],["\u003cp\u003eIf multiple meal types are logged, the \u003ccode\u003emeal_type\u003c/code\u003e field will be set to \u003ccode\u003eUNKNOWN\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eMissing nutrition values for a given time period result in an empty dataset for that period.\u003c/p\u003e\n"]]],[],null,["# Read Aggregate Daily Nutrition Data\n\nThis section demonstrates reading the aggregate daily nutrition from a specific\ndata source. The response contains a list of buckets (one per 24-hour period),\neach with a single dataset and datapoint that contains a field for all recorded\nnutrition data types. If no nutrition values exist for a particular time\nperiod, there is no dataset. If more than one `meal_type` is recorded, the\nvalue will be set to `UNKNOWN`. \n\n### Android\n\nYour app can read the aggregate daily nutrition data for a user by creating\na data read request, and specifying the aggregate for the\n['DataType.TYPE_NUTRITION'](/android/reference/com/google/android/gms/fitness/data/DataType#TYPE_NUTRITION) and\n['DataType.AGGREGATE_NUTRITION_SUMMARY'](/android/reference/com/google/android/gms/fitness/data/DataType#AGGREGATE_NUTRITION_SUMMARY) data types, as shown in the\nfollowing example: \n\n val readRequest = DataReadRequest.Builder()\n .aggregate(DataType.AGGREGATE_NUTRITION_SUMMARY)\n .bucketByTime(1, TimeUnit.DAYS)\n .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)\n .build()\n\n### REST\n\nYour app can read the aggregate daily nutrition data for a user by\nmaking a `POST` request and querying the specified data source. You must\nmake a separate query for each data source.\n\n**HTTP method** \n\n POST\n\n**Request URL** \n\n https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate\n\n**Request body** \n\n {\n \"aggregateBy\": [{\n \"dataSourceId\":\n \"raw:com.google.nutrition:407408718192:MyDataSource\"\n }],\n \"bucketByTime\": { \"durationMillis\": 86400000 },\n \"startTimeMillis\": 1471244400000,\n \"endTimeMillis\": 1471259040000\n }\n\n**Response**\n\nIf the data source is created successfully, the response is a `200 OK`\nstatus code. The response body contains a JSON representation of the data\nsource, including a `datasource.dataStreamId` property that you can use as\nthe data source 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 @aggregate.json \\\n https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"]]