2 回答

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

TA貢獻(xiàn)1833條經(jīng)驗 獲得超4個贊
太棒了,所以在評論中得到一些支持后,我有一些工作代碼可以使用 3 個 API 調(diào)用添加一個包含來自先前定義的數(shù)據(jù)源的數(shù)據(jù)的新會話。第一個調(diào)用是創(chuàng)建數(shù)據(jù)源,只需要運(yùn)行一次。然后第二個和第三個將數(shù)據(jù)點(diǎn)添加到數(shù)據(jù)集中并分別為鍛煉創(chuàng)建一個新會話。這是最終的工作代碼:
數(shù)據(jù)源:
/*
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); });
*/
數(shù)據(jù)和數(shù)據(jù)集:
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')
添加回答
舉報