在我的应用中,我正在使用“汇总”功能从Google Fit数据集中请求数据。此方法适用于心率,速度,距离等,但已停止(但之前一直在工作)用于位置数据。
这是我正在使用的请求模板:
POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
{
"aggregateBy": [
{
"dataTypeName": "com.google.location.sample"
}
],
"endTimeMillis": xxxx,
"startTimeMillis": xxxx
}
对于dataTypeName ==“ com.google.location.sample”,请求将返回:
403
- Show headers -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "No permission to read data for this private data source."
}
],
"code": 403,
"message": "No permission to read data for this private data source."
}
}
为什么位置数据是私有的? Google发生了变化吗 API方面?有其他方法可以请求位置数据吗?
这些是我的应用有权使用的范围:
"https://www.googleapis.com/auth/fitness.activity.read",
"https://www.googleapis.com/auth/fitness.body.read",
"https://www.googleapis.com/auth/fitness.location.read",
"https://www.googleapis.com/auth/fitness.nutrition.read"
请注意,列表中包含“ fitness.location.read”。
谢谢您的建议。
答案 0 :(得分:0)
我也尝试从Google Fit中获取数据,但只是针对“步骤”,有时还会获得状态为403的响应
请求:
POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
$headers = [
'Authorization' => 'Bearer ' . $access_token,
'Content-Type' => 'application/json',
];
$body = [
"aggregateBy" => [
[
"dataTypeName" => "com.google.step_count.delta",
"dataSourceId" =>
"derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
],
[
"dataTypeName" => "com.google.distance.delta",
"dataSourceId" =>
"derived:com.google.distance.delta:com.google.android.gms:merge_distance_delta"
]
],
"bucketByTime" => ["durationMillis" => xxxx],
"startTimeMillis" => xxxx,
"endTimeMillis" => xxxx
];
响应:
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "datasource not found (truncated...)
POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate` resulted in a `403 Forbidden` response:
决定:
关于错误403的所有描述,您可以在这里看到:
this comment on nodejs-dialogflow
要解决此问题,您可以尝试执行以下算法:https://developers.google.com/analytics/devguides/reporting/core/v3/errors 或您的用户应具有足够的权限(403“ insufficientPermissions”)