將特定類型或串流的資料匯總到值區中,並除以指定的邊界類型。多個來源和多個來源的資料集可匯總至各個要求的單一值區類型。立即試用。
要求
HTTP 要求
POST https://www.googleapis.com/fitness/v1/users/userId/dataset:aggregate
參數
參數名稱 | 值 | 說明 |
---|---|---|
路徑參數 | ||
userId |
string |
所識別身分的匯總資料。使用 me 表示已驗證的使用者。目前僅支援 me 。
|
授權
此要求需要至少具備下列其中一個範圍的授權:
範圍 |
---|
https://www.googleapis.com/auth/fitness.activity.read |
https://www.googleapis.com/auth/fitness.activity.write |
https://www.googleapis.com/auth/fitness.location.read |
https://www.googleapis.com/auth/fitness.location.write |
https://www.googleapis.com/auth/fitness.body.read |
https://www.googleapis.com/auth/fitness.body.write |
https://www.googleapis.com/auth/fitness.nutrition.read |
https://www.googleapis.com/auth/fitness.nutrition.write |
https://www.googleapis.com/auth/fitness.blood_pressure.read |
https://www.googleapis.com/auth/fitness.blood_pressure.write |
https://www.googleapis.com/auth/fitness.blood_glucose.read |
https://www.googleapis.com/auth/fitness.blood_glucose.write |
https://www.googleapis.com/auth/fitness.oxygen_saturation.read |
https://www.googleapis.com/auth/fitness.oxygen_saturation.write |
https://www.googleapis.com/auth/fitness.body_temperature.read |
https://www.googleapis.com/auth/fitness.body_temperature.write |
https://www.googleapis.com/auth/fitness.reproductive_health.read |
https://www.googleapis.com/auth/fitness.reproductive_health.write |
詳情請參閱驗證與授權頁面。
要求主體
在要求內容中,請按照下列結構提供資料:
{ "startTimeMillis": long, "endTimeMillis": long, "aggregateBy": [ { "dataTypeName": string, "dataSourceId": string } ], "filteredDataQualityStandard": [ string ], "bucketByTime": { "durationMillis": long, "period": { "type": string, "value": integer, "timeZoneId": string } }, "bucketBySession": { "minDurationMillis": long }, "bucketByActivityType": { "minDurationMillis": long, "activityDataSourceId": string }, "bucketByActivitySegment": { "minDurationMillis": long, "activityDataSourceId": string } }
資源名稱 | 值 | 說明 | 附註 |
---|---|---|---|
startTimeMillis |
long |
時間範圍的開始時間。與這個時間範圍內的交集資料會匯總。時間以毫秒為單位 (自 Epoch 起算), | |
endTimeMillis |
long |
回溯期結束。與這個時間範圍內的交集資料會匯總。時間以毫秒為單位 (自 Epoch 起算), | |
aggregateBy[] |
list |
要匯總的資料規格。必須提供至少一個 AggregateBy 規格。所有指定資料都會以相同的儲存條件匯總。每個匯總 By 規格都會有一個資料集。 | |
aggregateBy[].dataTypeName |
string |
要匯總的資料類型。所有提供這個資料類型的資料來源都會將資料匯總至匯總資料。回應中會包含這個資料類型名稱的單一資料集。資料集將會包含資料來源的資料來源 ID: | |
aggregateBy[].dataSourceId |
string |
要匯總的資料來源 ID。只有指定資料來源 ID 的資料會納入匯總作業。指定這個資料來源時,這個資料來源必須已存在,針對提供的憑證,OAuth 範圍必須授予這個資料類型的讀取權限。回應中的資料集將有相同的資料來源 ID。注意:資料可依 dataTypeName 或 dataSourceId 進行匯總,無法同時匯總兩者。 | |
filteredDataQualityStandard[] |
list |
請勿填入這個欄位。系統會忽略這則訊息。 | |
bucketByTime |
nested object |
指定按單一時間間隔匯總資料。無法與其他值區規格搭配使用。 | |
bucketByTime.durationMillis |
long |
指定結果值區的匯總時間長度 (毫秒) 匯總資料。無資料的時間範圍會包含回應中。 | |
bucketByTime.period |
nested object |
||
bucketByTime.period.type |
string |
可接受的值如下:
|
|
bucketByTime.period.value |
integer |
||
bucketByTime.period.timeZoneId |
string |
org.joda.timezone.DateTimeZone | |
bucketBySession |
nested object |
指定按使用者工作階段匯總資料。凡是不在工作階段時間範圍內的資料,都不會納入回應。無法與其他值區規格搭配使用。 | |
bucketBySession.minDurationMillis |
long |
指定只將持續時間超過 minDurationMillis 的工作階段視為匯總,並用來當做匯總資料的容器。 | |
bucketByActivityType |
nested object |
說明系統會根據記錄資料時的活動類型匯總資料。在特定活動類型中記錄的所有資料 (在指定時間範圍內所記錄的資料) 都會匯總至同一個值區。使用者閒置期間所記錄的資料不會納入回應中。無法與其他值區規格搭配使用。 | |
bucketByActivityType.minDurationMillis |
long |
指定只將持續時間超過 minDurationMillis 的活動區段納入考量,並做為匯總資料的容器。 | |
bucketByActivityType.activityDataSourceId |
string |
如未指定特定 ActivityDataSourceId,則使用預設活動串流。 | |
bucketByActivitySegment |
nested object |
指定系統會針對使用者記錄的每個活動區隔匯總資料。與 bucketByActivitySegment 相似,但每個活動區隔而非在同類型的所有區隔中完成。無法與其他值區規格搭配使用。 | |
bucketByActivitySegment.minDurationMillis |
long |
指定只將持續時間超過 minDurationMillis 的活動區段納入考量,並做為匯總資料的容器。 | |
bucketByActivitySegment.activityDataSourceId |
string |
如未指定特定 ActivityDataSourceId,則使用預設活動串流。 |
回應
如果成功的話,這個方法會傳回回應內文,其結構如下:
{ "bucket": [ { "type": string, "startTimeMillis": long, "endTimeMillis": long, "dataset": [ users.dataSources.datasets Resource ], "session": { "id": string, "name": string, "description": string, "startTimeMillis": long, "endTimeMillis": long, "modifiedTimeMillis": long, "application": { "packageName": string, "version": string, "detailsUrl": string, "name": string }, "activityType": integer, "activeTimeMillis": long }, "activity": integer } ] }
屬性名稱 | 值 | 說明 | 附註 |
---|---|---|---|
bucket[] |
list |
包含匯總資料的值區清單。 | |
bucket[].type |
string |
值區類型代表值區內的資料匯總執行方式。 可接受的值如下:
|
|
bucket[].startTimeMillis |
long |
匯總資料的開始時間,以 Epoch 紀元時間 (含) 為單位 (以毫秒為單位)。 | |
bucket[].endTimeMillis |
long |
匯總資料的結束時間,以 Epoch 紀元時間 (含) 為單位 (以毫秒為單位)。 | |
bucket[].dataset[] |
list |
要求中會顯示一個 AggregateBy 的資料集。 | |
bucket[].session |
nested object |
適用於值區.Type.SESSION | |
bucket[].session.id |
string |
用戶端產生的 ID,在特定使用者擁有的所有工作階段中都不會重複。 | |
bucket[].session.name |
string |
使用者可理解的工作階段名稱。 | |
bucket[].session.description |
string |
工作階段說明。 | |
bucket[].session.startTimeMillis |
long |
開始時間,以毫秒為單位 (自 Epoch 起算), | |
bucket[].session.endTimeMillis |
long |
結束時間 (以毫秒為單位,自 Epoch 起算,含首尾)。 | |
bucket[].session.modifiedTimeMillis |
long |
表示工作階段上次修改時間的時間戳記。 | |
bucket[].session.application |
nested object |
建立工作階段的應用程式。 | |
bucket[].session.application.packageName |
string |
這個應用程式的套件名稱。建立 Android 應用程式時會用來當做專屬 ID,但 REST 用戶端無法指定。REST 用戶端的開發人員 ID 號碼會反映在資料來源資料串流 (而非 packageName) 中。 | |
bucket[].session.application.version |
string |
應用程式的版本。只要應用程式變更了會影響資料運算的方式,您就應該更新這個欄位。 | |
bucket[].session.application.detailsUrl |
string |
選用的 URI 可用來連結應用程式。 | |
bucket[].session.application.name |
string |
這個應用程式的名稱。對 REST 用戶端來說,這是必要步驟,但我們不會強制使用這個名稱。它可供其他開發人員辨識,以便找出哪個 REST 建立應用程式或資料來源。 | |
bucket[].session.activityType |
integer |
這個工作階段代表的活動類型。 | |
bucket[].session.activeTimeMillis |
long |
工作階段有效時間。雖然 start_time_millis 和 end_time_millis 定義了整個工作階段時間,但活動時間可以較短,而 Active_time_millis 有效。如果已知工作階段期間的閒置時間,系統也應透過 com.google.activity.Segment 資料點與 STILL 活動值插入 |
|
bucket[].activity |
integer |
適用於值區.Type.Activity_TYPE、bucket.Type.Activity_SEGMENT |
試試看!
使用 APIs Explorer 針對即時資料呼叫這個方法,並查看回應。