Fitbit Integration

Use Point SDK to allow your users to integrate their Point and Fitbit accounts.

Overview

When you integrate your app with Fitbit, Point Health Service will subscribe to Fitbit to collect the end-user data and generate metrics. However, we must provide a way for the user to authenticate their account and give Point authorization to subscribe to Fitbit data.

This article will cover all steps necessary to provide full Fitbit integration to your Point-powered application.

  1. Integrate your app with Fitbit.

  2. Create a custom URL for your app in Xcode.

  3. Set up the SDK with your Fitbit Client ID.

  4. Call the Fitbit authentication method.

As this integration is mostly done in Point's backend, it is available regardless of device type.

Fitbit Integration

The first step to using Fitbit within Point SDK is integrating your app with Fitbit. We have a step-by-step tutorial here.

Setting Up

Calling setupFitbitIntegration(fitbitClientId:) will instantiate FitbitIntegrationManager within the SDK and it will be available for you to use.

import {AppRegistry} from 'react-native';
import PointSdkRn from "react-native-point-sdk";

AppRegistry.registerComponent(appName, () => {
  PointSdkRn.setup('clientID', 'clientSecret', 'development', true, () =>
    console.log('Setup completed!'),
  );

  PointSdkRn.setupFitbitIntegration('fitbitClientId', () =>
    console.log('Setup Fitbit completed!'),
  );

  return App;
});

Tip: Your Fitbit Client ID is provided by Fitbit when you create your Fitbit app integration.

Important: You also must have a user token set to handle your user's Fitbit authentication. Check Getting Started for more information.

Authentication

Each user will need to individually authenticate their Fitbit account within Point SDK and give Point permission to get their Fitbit data. This is done on a Fitbit's web page, although the SDK is capable of loading a browser session that displays the authentication page. After some simple project setup, all you will need to do is call an SDK method when you wish to trigger the authentication flow.

Create a custom URL

As the authentication is handled by a browser session, the browser must know how to handle the control back to your app. For this, we can use a custom URL scheme that, when called by the browser, redirects to your app and dismisses the browser.

  1. Go to your project settings on xcode and select your app target.
  2. Under the Info tab, look for URL Types and click "+" to add a new one.
  3. In the Identifier field, enter your app's Bundle ID.
  4. In the URL Schemes field, enter the scheme you used in the callbackURL when creating your app integration with Fitbit. For example, if your callbackURL is "https://exampleApp/auth", use "exampleApp". Custom URL.

For more information, check the official docs: Defining a Custom URL Scheme for Your App

Authenticating

To display the authentication web page, call authenticate(callbackURLScheme: scopes:).

When you call this function your app will display a browser with the Fitbit authentication web page. If the user successfully authenticates, the browser will be dismissed and the control will be handled back to your app.

Tip: The callbackUrlScheme parameter is the scheme created in the previous section.

const authenticateFitbit = async () => {
    try {
      const result = await PointSdkRn.authenticateFitbit('sampleapp', [
        FitbitScopes.Activity,
        FitbitScopes.Heartrate,
        FitbitScopes.Profile,
      ]);
      console.log(result);
    } catch (error) {
      console.log(error);
    }
}

If you wish to select specific Fitbit scopes, use the scopes parameter. All scopes are selected by default. Check Fitbit Official Documentation to know more about scopes.

The user will be requested to provide authorization for each scope subscription, so data will be collected only if the user provides authorization.

After successful authentication, Point will retroactively retrieve one year of Fitbit data. After this, the subscriptions are created and Point will be notified for each new user data. No further action is necessary for the SDK. Check Health Data Service to know how to have access to Point's generated metrics.

Revoke

You can revoke all Fitbit subscriptions of the user by calling revokeFitbitAuthentication().

const revokeFitbitAuthentication = async () => {
    try {
      await PointSdkRn.revokeFitbitAuthentication();
      console.log('Successfully logged out');
    } catch (error) {
      console.log(error);
    }
  };

After calling this, Point Health Service will stop receiving new data from Fitbit.

Download our App

Download the app on App Store

Connect with Us

Terms & Conditions | Privacy Policy © 2022 Point® (Key Point Technologies, Inc.)