1

I am trying to create an app using Google Fit Api and i am trying to get the total time of exercise (supposed that the exercise is walking) for the user. What i want basically is to get the value marked in below image :

Google Fit Time Screenshot

I was thinking to work with sessions (https://developers.google.com/fit/android/using-sessions) but i prefer to skip this if there is already something provided by Google. I know how to get the daily steps/calories/distance but i am not able to find anything to get the daily exercise time.

stake
  • 21
  • 1
  • 3

1 Answers1

1

Let me describe what I found so far, but there is one issue left...

You can use the aggregate api and group by activity type. Here is an example with daily bucketing:

POST https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate

{
    "aggregateBy": [
        {
            "dataSourceId": "derived:com.google.activity.segment:com.google.android.gms:merge_activity_segments"
        }
    ],
    "endTimeMillis": "1481788800000",
    "startTimeMillis": "1481702400000",
    "bucketByTime": {
        "period": {
            "timeZoneId": "America/Los_Angeles",
            "type": "day",
            "value": 1
        }
    }
}

The call will return a number of records, each containing three values: activity type, duration in milliseconds, and number of segments. You can find the activity types at: https://developers.google.com/fit/rest/v1/reference/activity-types. You can add up the milliseconds for the activity types you are interested in.

Now, the issue - I have seen examples of mismatch of activity types between the API and Fit app. I don't know how widespread the mismatch is. See my question: Getting active time from Google Fit Rest API.

Community
  • 1
  • 1
AlexR
  • 240
  • 1
  • 11
  • Thank you for your reply. I missed to mention that i am not using REST APIs but API for android. Anyhow i am able to find and use the aggregate data. – stake Dec 19 '16 at 07:35