如何从谷歌的REST API获取睡眠数据?



我正在尝试从Google-Fit获取我的睡眠数据。

当我发出以下请求时-

const { data: sleepData } = await axios({
method: 'POST',
url: 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate',
headers: {
Authorization: `Bearer ${accessToken}`,
},
data: {
aggregateBy: [{ dataTypeName: 'com.google.sleep.segment' }],
bucketByTime: { durationMillis: 86400000 },
startTimeMillis: startTimeQuery, // day start time in UNIX
endTimeMillis: endTimeQuery, // day end time in UNIX
},
});

我得到以下数据与空点-

{
"bucket": [
{
"startTimeMillis": "1651115600000",
"endTimeMillis": "1651202000000",
"dataset": [
{
"dataSourceId": "derived:com.google.sleep.segment:com.google.android.gms:merged",
"point": []
}
]
},
{
"startTimeMillis": "1651202000000",
"endTimeMillis": "1651288400000",
"dataset": [
{
"dataSourceId": "derived:com.google.sleep.segment:com.google.android.gms:merged",
"point": []
}
]
},
]}

有人遇到类似的问题吗?

我在Android设备上使用Google-Fit。

嘿,这是一个工作的例子,从谷歌健身REST API与我的帐户连接到我的睡眠跟踪设备。

var axios = require('axios');
var data = JSON.stringify({
"aggregateBy": [
{
"dataTypeName": "com.google.sleep.segment"
}
],
"endTimeMillis": {endTimeMillis},
"startTimeMillis": {startTimeMillis}
});
var config = {
method: 'post',
url: 'https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate',
headers: { 
'Authorization': 'Bearer {AccessToken}', 
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});

唯一的区别是删除bucketByTime这样Fitness API会发送尽可能小的段点。

相关内容

  • 没有找到相关文章