I am calling the google fit API for the activity between two dates but how do I just get the Activity integers? Is there a direct way to call it from the HTTP request or do I have to filter the JSON data myself?
social_token = SocialToken.objects.get(account__user=2)
token=social_token.token
url = "https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate"
headers = {
"Authorization": "Bearer {}".format(token),
"Content-Type": "application/json"
}
body = {
"aggregateBy": [{
"dataTypeName": "com.google.activity.segment",
}],
"startTimeMillis": 1634767200000,
"endTimeMillis": 1634853600000
}
respo = requests.post(url, data=json.dumps(body), headers=headers)
The JSON response
[
"{\n \"bucket\":
[\n {\n \"startTimeMillis\": \"1634767200000\",\n \"endTimeMillis\": \"1634853600000\",\n \"dataset\":
[\n ",
" {\n \"dataSourceId\": \"derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments\",\n \"",
"point\":
[\n {\n \"startTimeNanos\": \"1634818320000000000\",\n \"endTimeNanos\": \"163482012000000000",
"0\",\n \"dataTypeName\": \"com.google.activity.segment\",\n \"originDataSourceId\": \"raw:com.google.activity.se",
"gment:com.google.android.apps.fitness:user_input\",\n \"value\": [\n {\n \"intVal\": 97,\n ",
" \"mapVal\": []\n }\n ]\n },\n {\n \"startTimeNanos\": \"163",
"4820120000000000\",\n \"endTimeNanos\": \"1634820292573000000\",\n \"dataTypeName\": \"com.google.activity.segme",
"nt\",\n \"value\": [\n {\n \"intVal\": 7,\n \"mapVal\": []\n }\n",
" ]\n },\n {\n \"startTimeNanos\": \"1634823157245000000\",\n \"endTimeNanos\"",
": \"1634823301721000000\",\n \"dataTypeName\": \"com.google.activity.segment\",\n \"value\": [\n {",
"\n \"intVal\": 7,\n \"mapVal\": []\n }\n ]\n }\n ]\n ",
" }\n ]\n }\n ]\n}\n"
]