# Get SpO2 Data
TIP
This guide assumes that your app has already been authorized and the snippet of code that I will show you can access to a valid FitbitCredentials
instance, here called fitbitCredentials
, the Fitbit OAuth 2.0 client ID, here called clientID
, and the Fitbit client secret, here called clientSecret
.
SpO2 data (opens new window) contain details about a user's SpO2 data. In Fitbitter, a datapoint is expressed by the FitbitSpO2Data
model.
In particular, an instance of FitbitSpO2Data
has the following fields:
/// The user encoded id.
String? userID;
/// The date of monitoring of the data.
DateTime? dateOfMonitoring;
/// The average value of the data.
double? avgValue;
/// The minimum value of the data.
double? minValue;
/// The maximum value of the data.
double? maxValue;
An example is:
FitbitSpO2Data(userID: 7ML2XV, dateOfMonitoring: 2022-05-08 00:00:00.000, avgValue: 97.2, minValue: 94.4, maxValue: 99.8,)
Information about the user's SpO2 data can be obtained in three steps:
# Step 1: Instanciate a manager
First, you need to instanciate a FitbitSpO2DataManager
FitbitSpO2DataManager fitbitSpO2DataManager = FitbitSpO2DataManager(
clientID: '<OAuth 2.0 Client ID>',
clientSecret: '<Client Secret>',
);
# Step 2: Create the request url
Then, you have to create a url object, FitbitSpO2APIURL
to fetch the SpO2 data as:
FitbitSpO2APIURL fitbitSpO2APIURL = FitbitSpO2APIURL.day(
date: DateTime.now(),
fitbitCredentials: fitbitCredentials,
);
where date
is the day you want to fetch FitbitSpO2Data
from and fitbitCredentials
is the FitbitCredentials
instance obtained during the authentication step.
TIP
For the complete list of possible FitbitSpO2APIURL
, defined for different time ranges, please refer to the API Doc (opens new window).
# Step 3: Get the data
Finally you can obtain the SpO2 data using
List<FitbitSpO2Data> fitbitSpO2Data = await fitbitSpO2DataManager.fetch(fitbitSpO2APIURL);