简体   繁体   中英

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. 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; the latter takes precedence, so this will only return data if the estimated_steps stream contains data on the server.

I'd suggest removing the dataSourceId , then the default data source for step_count.delta will be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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