2 回答

TA貢獻1835條經驗 獲得超7個贊
看起來您可能試圖為數據類型傳遞錯誤的字段:如果您想使用標準數據類型(如com.google.heart_minutes
),您應該傳遞標準數據類型的確切字段(字段應稱為“強度”);或者只是傳遞數據類型名稱,后端將為您填寫它們。
因此,如果您將數據類型更改為
"dataType": {"name": "com.google.heart_minutes"}
它應該工作。
然后,您需要使用從該請求返回的數據源 ID 來獲取數據點。

TA貢獻1833條經驗 獲得超4個贊
太棒了,所以在評論中得到一些支持后,我有一些工作代碼可以使用 3 個 API 調用添加一個包含來自先前定義的數據源的數據的新會話。第一個調用是創建數據源,只需要運行一次。然后第二個和第三個將數據點添加到數據集中并分別為鍛煉創建一個新會話。這是最終的工作代碼:
數據源:
/*
gapi.client.fitness.users.dataSources.create({
"userId":"me",
"resource": {
"application": {
"name": "LittleWorkouts"
},
"dataType": {
"name": "com.google.heart_minutes"
},
"device": {
"manufacturer": "op",
"model": "6",
"type": "phone",
"uid": "1000020",
"version": "1"
},
"type": "raw"
}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error 1", err); });
*/
數據和數據集:
gapi.client.fitness.users.dataSources.datasets.patch({
"dataSourceId":"raw:com.google.heart_minutes:108881196053:op:6:1000020",
"userId": "me",
"datasetId": z,
"resource": {
"minStartTimeNs": workoutStartTime * 1000000,
"maxEndTimeNs": workoutEndTime * 1000000,
"dataSourceId": "raw:com.google.heart_minutes:108881196053:op:6:1000020",
"point": [
{
"originDataSourceId": "raw:com.google.heart_minutes:108881196053:op:6:1000020",
"value": [
{
"fpVal": 8
}
],
"dataTypeName": "com.google.heart_minutes",
"endTimeNanos": workoutEndTime * 1000000,
"startTimeNanos": workoutStartTime * 1000000,
}
]
}
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error 2", err); });
會議:
gapi.client.fitness.users.sessions.update({
"userId":"me",
"sessionId": id,
"id": id,
"name": "Morning Workout",
"description": "A very intense workout",
"startTimeMillis": workoutStartTime,
"endTimeMillis": workoutEndTime,
"version": 1,
"lastModifiedToken": "exampleToken",
"application": {
"detailsUrl": "http://example.com",
"name": "LittleWorkouts",
"version": "1.0"
},
"activityType": 21,
"activeTimeMillis": workoutEndTime - workoutStartTime
}).then((res) => {console.log(res)});
console.log('res')
添加回答
舉報