Overview
Google Fit helps you to track your fitness data. The Google Fitness REST APIs, on the other hand, allow the developers to extend this further and create customized dashboards. Google Fitness REST APIs are useful if you have a fitness app and you want to integrate your data with Google Fit or if you just want to collect the fitness data and display some information to the users.
In this article, we are going to explore Google Fitness REST APIs and the Google Developer playground to start programming with REST APIs. Please refer to my previous article for the Overview of Google Fit API.
Get Started with REST API
Google Account
The one and important prerequisite is that you should have a Google account. If you do not have, create one from here.
Generate OAuth 2.0 client ID
- Open Google API Console from here.
- Select any existing project or choose to create a new project.
- Click "Continue".

- Once the project is created, we will have to generate the credentials.
- Click “Go to credentials”.

- Select the options as highlighted below.

- Click “What credentials do I need?”
- Under Authorized JavaScript origins, add https://developers.google.com
- Under Authorized Redirect URI, add https://developers.google.com/oauthplayground

- Click “Create OAuth client ID”.
- Set up the OAuth 2.0 consent screen.

- Click "Continue".
- The Client id will be generated. Note it down for future use.

- Click "Done".
Google Developer Playground
The OAuth 2.0 Playground for Google Developers platform can be accessed from https://developers.google.com/oauthplayground. This playground will help the developers to explore various Google APIs, understand their requests and responses, and query the APIs to fetch the data. In this article, we are going to explore the Fitness APIs out of available loads of various APIs.
- Open OAuth 2.0 Playground.
- Locate “Fitness V1” API.
- Select the scopes under it that you want to query to.

- Click "Authorize APIs".
- In the next screen, choose the Google account to be used.

- In the confirmation screen, verify the selected scopes.

- Click "Allow".
- In the next screen, click “Exchange authorization code for tokens”.
List all Data Sources
Google manages the data through data sources. To see all the data sources, use the below request URI.
- https://www.googleapis.com/fitness/v1/users/me/dataSources

In the response, all the available data sources for the user (me) will be listed along with the data types. derived:com.google.step_count.delta:com.google.android.gms:estimated_steps is one of the example which gives the number of steps.
Get the Number of Steps
We will use the available data source derived:com.google.step_count.delta:com.google.android.gms:estimated_steps to get the steps.
- Change the HTTP method to POST.
- In the Request URI, type https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate.
- Click “Enter request body”. Enter the below request body.
- {
- "aggregateBy" : [{
- "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
- }],
- "bucketByTime": { "durationMillis": 86400000 }, // This is 24 hours
- "startTimeMillis": 1546210381932, // Start time
- "endTimeMillis": 1547210381932 // End Time
- }

- Click "Close".
- Click "Send the request".
- The response will appear on the right.

- Sum up all the intVal (highlighted above) to get the number of steps. Each intVal indicates the steps for an individual activity at a different time within the specified time span.
Get the start date and end date
We can use plain JavaScript to get the start date.
- new Date().getTime()
Summary
Google Fitness REST APIs allow performing operations on various available data sources. The Google Developer Playground helps start programming with REST APIs to get the actual data.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Rajat AnandPosted Aug 10, 2020, 4:59 AM
On clicking 'Exchange authorization code for tokens', nothing is happening
Parimi ChowdaryPosted Aug 7, 2020, 12:16 AM
I Have implemented below code to get yesterday steps count for registered users. But sometime few users data returning is null . FitnessAggregate fitnessAggregate = new FitnessAggregate() { StartTimeMillis = new DateTimeOffset(DateTime.Today.AddDays(-1)).ToUnixTimeMilliseconds(), EndTimeMillis = new DateTimeOffset(DateTime.Today.AddMilliseconds(-1)).ToUnixTimeMilliseconds() }; BucketByTime bucketByTime = new BucketByTime() { DurationMillis = 86400000 }; AggregateBy[] aggregates = new AggregateBy[] { new AggregateBy() { DataSourceId = "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps" } }; fitnessAggregate.AggregateBy = aggregates; fitnessAggregate.BucketByTime = bucketByTime; return JsonSerializer.Serialize(fitnessAggregate);
Nanddeep NachanPosted Aug 2, 2019, 3:11 AM
Hi Maree, The manually added activity end up getting a merged value.
Maree NuriraPosted Jul 30, 2019, 8:54 AM
Pls advise, if user doesn't has step for datasoruce example "derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas" if we need from them.
Naseeb VpPosted Jul 16, 2019, 12:41 AM
Is it possible to list fitness details of multiple users using google fit REST API.if not what will be the solution for that
om parmarPosted Jul 8, 2019, 5:45 AM
Google Rest Api Provide any API To call in ios application ? Ans Me fast
om parmarPosted Jul 8, 2019, 5:44 AM
How i can use it in IOS application Devlopment?
Ken DraperPosted Jan 27, 2019, 11:46 AM
Great article. Can you return the google map route( longitude and latitude) that shows in google fit when you record a walk or run.