I am using google fit android app for my daily fitness activity monitoring. Based on this, I thought of integrating Google Fitbit with Salesforce. This blog will give step by step process of integrating Google Fitbit/Fit with Salesforce.
This complete integration require below step
- Get Access Token from Google to call Google Fit API
- Get activities using above token in Apex and Lightning Component
- Show activities in Line Chart
1. Get Access Token from Google to call Google Fit API
Please refer blog http://salesforcecodex.com/2020/02/integrating-google-api-with-salesforce/ to get access token for Google Fit API.
2. Get activities in Apex and Lightning Component
Once we get access token from above step. We can get daily activities by calling Google Fit REST API. There are number of REST API to get different kind of activities. We are using https://www.googleapis.com/fitness to get aggregate of daily activities.
You can find list of available activities at https://developers.google.com/fit/rest/v1/reference/users/dataset/aggregate in scope section.
This API need start and end data with short duration like 1 Hour to check data. We can give multiple requests for getting complete 24 hrs data. This is just for blog purpose where I want to show hourly data. You can get data based on your requirement.
3. Show activities in Line Chart
We will get our hourly data based on user authenticated. Let us call above Apex service and show activity in chart. We will use chartjs library to show chart. Download Chartjs library (Chart.min.js) and add to static resource as chart.
We have used lightning:progressBar to show progress indicator while retrieving fitness data.