简体   繁体   English

如何获取每周 Google Fit Rest API 数据

[英]How to get weekly Google Fit Rest API data

I am trying to get my weekly aggregated step count from Google Fit using their REST Api following their documentation but the point data is coming back empty.我正在尝试按照他们的文档使用他们的 REST Api 从 Google Fit 获取我每周汇总的步数,但点数据返回空。 I have enabled read location and activity scope for the access token.我已启用访问令牌的读取位置和活动范围。 My code :我的代码:

import json
import requests

api_url = "https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"

access_token = ""

headers = {
  "Authorization": "Bearer {}".format(access_token),
  "Content-Type": "application/json;encoding=utf-8"
  }

body = {
  "aggregateBy": [{
    "dataTypeName": "com.google.step_count.delta",
    "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
  }],
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1438705622000,
  "endTimeMillis": 1439310422000
}


response = requests.post(api_url, data=json.dumps(body), headers=headers)

print(response.text)
  "aggregateBy": [{
    "dataTypeName": "com.google.step_count.delta",
    "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
  }],

Your aggregateBy specifies both the data type name and data source id;您的aggregateBy指定了数据类型名称和数据源ID; the latter takes precedence, so this will only return data if the estimated_steps stream contains data on the server.后者优先,因此只有当estimated_steps流包含服务器上的数据时,它才会返回数据。

I'd suggest removing the dataSourceId , then the default data source for step_count.delta will be used.我建议删除dataSourceId ,然后将使用step_count.delta的默认数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM