Home SalesforceApex Google FitBit Integration with Salesforce

Google FitBit Integration with Salesforce

by Dhanik Lal Sahni

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

  1. Get Access Token from Google to call Google Fit API
  2. Get activities using above token in Apex and Lightning Component
  3. 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/

You may also like

8 comments

Kishan March 2, 2020 - 1:54 pm

cool … such a nice integration

Reply
Dhanik Lal Sahni May 3, 2020 - 9:06 am

Thank You Kishan. It is great that you look our blogs.

Regards
Dhanik Sahni

Reply
Surya Kumari M July 8, 2020 - 2:16 pm

Thank you so much Dhanik for this wonderful post. It really helped me to solve our issue.

Reply
Dhanik Lal Sahni July 9, 2020 - 11:42 am

Thank You Surya Kumari.

Reply
sam September 12, 2020 - 8:02 am

From where we can download ChartJs library. On click of chartjs in above documentation,i am getting File not found 404 error.

Reply
Dhanik Lal Sahni September 18, 2020 - 2:57 pm

Hello Sumit,
ChartJs library location is updated now in blog. Try once now.

Thank You,
Dhanik

Reply
sam September 14, 2020 - 10:01 am

Getting 404 resource not found error on Chart JS click.
Please suggest from where I can download the same.

Reply
Dhanik Lal Sahni September 18, 2020 - 2:58 pm

Hello Sam,

ChartJs library was moved at other place. I have updated location in blog. You can try now.

Thank You,
Dhanik

Reply

Leave a Comment