# Get Activity 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 data (opens new window) contain details about a user's activity. In Fitbitter, a datapoint is expressed by the FitbitActivityData
model.
Fitbitter fetches a simplified version of Activity data (opens new window) as described by Fitbit. In particular, an instance of FitbitActivityData
has the following fields:
/// The user encoded id.
String? userID;
/// The activity type id.
String? activityId;
/// The parent activity type id.
String? activityParentId;
/// The calories spent during the activity.
double? calories;
/// The description of the activity.
String? description;
/// The distance spanned during the activity.
double? distance;
/// The duration of the activity.
double? duration;
/// A flag that tells is the activity is the user's favorite.
bool? isFavorite;
/// The univocal activity id.
String? logId;
/// The name of the activity.
String? name;
/// The start date of the activity.
DateTime? dateOfMonitoring;
/// The start time of the activity.
DateTime? startTime;
An example is:
FitbitActivityData(userID: 7ML2XV, activityId: 90001, activityParentId: 90001, calories: 1383.0, dateOfMonitoring: 2022-05-08 00:00:00.000, description: Very Leisurely - Less than 10 mph, distance: 41.44793, duration: 6261000.0, isFavorite: false, logId: 47854564311, name: Bike, startTime: 2022-05-08 09:11:00.000, )
Information about the user's Activity data can be obtained in three steps:
# Step 1: Instanciate a manager
First, you need to instanciate a FitbitActivityDataManager
FitbitActivityDataManager fitbitActivityTimeseriesDataManager = FitbitActivityDataManager(
clientID: '<OAuth 2.0 Client ID>',
clientSecret: '<Client Secret>',
);
# Step 2: Create the request url
Then, you have to create a url object, FitbitActivityAPIURL
to fetch the Activity data as:
FitbitActivityAPIURL fitbitActivityApiUrl = FitbitActivityAPIURL.day(
date: DateTime.now(),
fitbitCredentials: fitbitCredentials,
);
where date
is the day you want to fetch FitbitActivityData from and fitbitCredentials
is the FitbitCredentials
instance obtained during the authentication step.
# Step 3: Get the data
Finally you can obtain the Activty data using
List<FitbitActivityData> fitbitActivityData = await fitbitActivityDataManager.fetch(fitbitActivityApiUrl);