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 an access token for Google Fit API.
2. Get activities in Apex and Lightning Component
Once we get the access token from the above step. We can get daily activities by calling Google Fit REST API. There are a number of REST APIs to get different kinds of activities. We are using https://www.googleapis.com/fitness to get an aggregate of daily activities.
You can find a list of available activities at https://developers.google.com/fit/rest/v1/reference/users/dataset/aggregate in scope section.
This API needs a start and end date with a 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.
Demo :
Reference:
https://developers.google.com/fit/rest
https://www.chartjs.org/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/
8 comments
cool … such a nice integration
Thank You Kishan. It is great that you look our blogs.
Regards
Dhanik Sahni
Thank you so much Dhanik for this wonderful post. It really helped me to solve our issue.
Thank You Surya Kumari.
From where we can download ChartJs library. On click of chartjs in above documentation,i am getting File not found 404 error.
Hello Sumit,
ChartJs library location is updated now in blog. Try once now.
Thank You,
Dhanik
Getting 404 resource not found error on Chart JS click.
Please suggest from where I can download the same.
Hello Sam,
ChartJs library was moved at other place. I have updated location in blog. You can try now.
Thank You,
Dhanik