# Get Activity Timeseries 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 the Fitbit user id, here called userID
, the Fitbit OAuth 2.0 client ID, here called clientID
, and the Fitbit client secret, here called clientSecret
.
Activity Timeseries data (opens new window) daily summary value over the specified date range for the given resource. In Fitbitter, a datapoint is expressed by the FitbitActivityTimeseriesData
model. In particular, an instance of FitbitActivityTimeseriesData
has the following fields:
/// The user encoded id.
String? userID;
/// The date of monitoring of the data.
DateTime? dateOfMonitoring;
/// The type of the activity timeseries data.
String? type;
/// The value of the data.
double? value;
An example is:
FitbitActivityTimeseriesData(userID: 7ML2XV, dateOfMonitoring: 2022-05-08 00:00:00.000, type: steps, value: 14036.0, )
Information about the user's Activity Timeseries data can be obtained in three steps:
# Step 1: Instanciate a manager
First, you need to instanciate a FitbitActivityTimeseriesDataManager
FitbitActivityTimeseriesDataManager fitbitActivityTimeseriesDataManager = FitbitActivityTimeseriesDataManager(
clientID: '<OAuth 2.0 Client ID>',
clientSecret: '<Client Secret>',
type: '<type>'
);
TIP
The <type>
field must be a valid string representing the type of Activity Timeseries data you need.
The possible values for <type>
are:
calories
caloriesBMR
steps
distance
floors
elevation
minutesSedentary
minutesLightlyActive
minutesFairlyActive
minutesVeryActive
activityCalories
# Step 2: Create the request url
Then, you have to create a url object, FitbitActivityTimeseriesAPIURL
, that fetches the specific Activty Timeseries data, specifying the same <type>
as above, during the desidered time range. For example:
FitbitActivityTimeseriesAPIURL fitbitActivityTimeseriesApiUrl = FitbitActivityTimeseriesAPIURL.dayWithResource(
date: DateTime.now(),
fitbitCredentials: fitbitCredentials,
resource: '<type>',
);
where date
is the day you want to fetch FitbitActivityTimeseriesData from and userID
is the Fitbit user's id obtained the authentication step.
For the complete list of possible FitbitActivityTimeseriesAPIURL
, defined for different time ranges, please refer to the API Doc (opens new window).
# Step 3: Get the data
Finally you can obtain the Activty Timeseries data using
List<FitbitActivityTimeseriesData> fitbitActivityTimeseriesData = await fitbitActivityTimeseriesDataManager.fetch(fitbitActivityTimeseriesApiUrl);