Search code examples
restgoogle-fitgoogle-fit-sdk

Get all running activities from Google Fit via REST API


Is there a way to get all activities from the Google fitness store via the REST API?

My current assumption is that other apps store their activities in sessions and I can retrieve them using Users.sessions.list. However, the information there, does not really include all the information that was stored or I would like to see: when I manually add a short run via the Fit Android app, I expect this information to be somehow accessible via the sessions API. This should at least include the information I have provided, such as distance or time.

Looking at the same information via the app or the web interface, I can see all the details I have previously entered plus the approximate number of steps and calories.

enter image description here

How do I get this information via the API?

I am currently mainly interested in activities of type running or jogging (8, 56-58) and would like to read the distance in addition to the time information already provided in the session.


Solution

  • Not sure, if this is the right way, but I get all the information I need, if I follow these steps

    1. Find the correct session via Users.sessions.list
    2. Query all data via Users.datasets.aggregate:
      • Set startTimeMillis and endTimeMillis to the values from the session in question
      • Set bucketBySession to group results by sessions.
      • I explicitly query all data sources: For every data source id I add a { "dataSourceId": <id>}to theaggregateBy` array. Not sure, if this is necessary

    The resulting bucket has all information related to the session. For my use case I need to clean up overloaded data: some data sources return the distance as steps (derived) while I need the physical length in meters.

    This seems to work for my Fit data with the additional cleaning, but I will need to check, if this works for other user's data too.