# Measure - GetActivity
WARNING
The data are only available once a synchronization occured between the device and Withings servers (which might include synchronizing with Withings mobile application or via Withings Mobile SDK).
Measure - GetActivity (opens new window) provides daily aggregated activity data of a user.
In WithingsFlutter, the response object is expressed by the WithingsMeasureGetActivityData. In particular, an instance of WithingsMeasureGetActivityData has the following fields:
/// Response status
int? status;
/// Array of objects (Activities)
List<Activities>? activities;
/// To know if there is more data to fetch or not
bool? more;
/// Offset to use to retrieve the next data
int? offset;
where Activities object is:
/// Date of the aggregated data
String? date;
/// Number of steps. (Use 'dataFields' to request this data)
int? steps;
/// Distance travelled (in meters). (Use 'dataFields' to request this data)
num? distance;
/// Number of floors climbed. (Use 'dataFields' to request this data)
num? elevation;
/// Duration of soft activities (in seconds). (Use 'dataFields' to request this data)
int? soft;
/// Duration of moderate activities (in seconds). (Use 'dataFields' to request this data)
int? moderate;
/// Duration of intense activities (in seconds). (Use 'dataFields' to request this data)
int? intense;
/// Sum of intense and moderate activity durations (in seconds). (Use 'dataFields' to request this data)
int? active;
/// Active calories burned (in Kcal). Calculated by mixing fine granularity calories estimation,
/// workouts estimated calories and calories manually set by the user. (Use 'dataFields' to request this data)
num? calories;
/// Total calories burned (in Kcal). Obtained by adding active calories and passive calories
num? totalcalories;
/// Average heart rate. (Use 'dataFields' to request this data)
int? hrAverage;
/// Minimal heart rate. (Use 'dataFields' to request this data)
int? hrMin;
/// Maximal heart rate. (Use 'dataFields' to request this data)
int? hrMax;
/// Duration in seconds when heart rate was in a light zone. (Use 'dataFields' to request this data)
int? hrZone0;
/// Duration in seconds when heart rate was in a moderate zone. (Use 'dataFields' to request this data)
int? hrZone1;
/// Duration in seconds when heart rate was in a intense zone. (Use 'dataFields' to request this data)
int? hrZone2;
/// Duration in seconds when heart rate was in a maximal zone. (Use 'dataFields' to request this data)
int? hrZone3;
TIP
For more info about the status check the Withings API documentation Response Status (opens new window) section.
TIP
For more info about these values/fields check the Withings API documentation Measure - GetActivity (opens new window) in the Query Parameters section.
For example:
WithingsMeasureGetActivityData(status: 0, activities: [Activities(date: 2022-09-08, steps: 643, distance: 504.75, elevation: 9.79, soft: 3600, moderate: 0, intense: 0, active: 0, calories: 19.679, totalcalories: 1656.683, hr_average: null, hr_min: null, hr_max: null, hr_zone_0: null, hr_zone_1: null, hr_zone_2: null, hr_zone_3: null, ), Activities(date: 2022-09-09, steps: 11969, distance: 15090.547, elevation: 141.12, soft: 4500, moderate: 420, intense: 3780, active: 4200, calories: 1012.122, totalcalories: 2653.711, hr_average: null, hr_min: null, hr_max: null, hr_zone_0: null, hr_zone_1: null, hr_zone_2: null, hr_zone_3: null, )], more: false, offset: 0, )
Informations about the daily aggregated activity data of a user can be obtained in three steps:
# Step 1: Instantiate a manager
First, you need to instanciate a WithingsMeasureGetActivityDataManager
WithingsMeasureGetActivityDataManager
withingsMeasureGetActivityDataManager =
WithingsMeasureGetActivityDataManager();
# Step 2: Create the request url
Then, you have to create a url object that can be of two different types that fetches the daily aggregated activity data of a user:
WithingsMeasureAPIURL.getActivityRangewhere you have to set the:accessTokenstartdateymdin theyyyy-mm-ddformat to define the range of time of data to be retrievedenddateymdin theyyyy-mm-ddformat to define the range of time of data to be retrieved
Then, if you want, you can set the:
dataFieldsis aString: a list of of requested data fields, separated by a commaoffset, if in the previous responsemore = true, so this means that there are more data to retrieve, so set inoffsetthe value ofoffsetof the previous response
WithingsMeasureAPIURL withingsMeasureAPIURLGetActivityRange =
WithingsMeasureAPIURL.getActivityRange(
startdateymd: '2022-09-08',
enddateymd: '2022-09-09',
//dataFields: 'hr_average,hr_zone_0', //Not necessary
//offset: , //Not necessary: use it if in the previous response more = true and insert here the value of offset
accessToken: withingsCredentials.withingsAccessToken);
WithingsMeasureAPIURL.getActivityLastupdatewhere you have to set the:accessTokenlastupdateas UNIX Timestamp for requesting data that were updated or created after this date
Then, if you want, you can set the:
dataFieldsis aString: a list of of requested data fields, separated by a commaoffset, if in the previous responsemore = true, so this means that there are more data to retrieve, so set inoffsetthe value ofoffsetof the previous response
WithingsMeasureAPIURL withingsMeasureAPIURLGetActivityLastupdate =
WithingsMeasureAPIURL.getActivityLastupdate(
lastupdate: 1662335635,
//dataFields: 'hr_average,hr_zone_0', //Not necessary
//offset: , //Not necessary: use it if in the previous response more = true and insert here the value of offset
accessToken: withingsCredentials.withingsAccessToken);
WARNING
Specifying dataFields seems not necessary, cause the results with or without are the same
TIP
For more info about the dataFields check the Withings API documentation Measure - GetActivity (opens new window) in the Query Parameters section.
# Step 3: Get the data
Finally you can obtain the daily aggregated activity data of a user using
WithingsMeasureGetActivityData getactivityrange =
await withingsMeasureGetActivityDataManager
.fetch(withingsMeasureAPIURLGetActivityRange);
or
WithingsMeasureGetActivityData getactivityupate =
await withingsMeasureGetActivityDataManager
.fetch(withingsMeasureAPIURLGetActivityLastupdate);
depending on the URL object.
But if you want the package to automatically handle the offset use the .fetchAutoOffset, instead of .fetch, of the manager, without specifying the offset in the field of the URL object:
WithingsMeasureGetActivityData getactivityrange =
await withingsMeasureGetActivityDataManager
.fetchAutoOffset(withingsMeasureAPIURLGetActivityRange);
WithingsMeasureGetActivityData getactivityupate =
await withingsMeasureGetActivityDataManager
.fetchAutoOffset(withingsMeasureAPIURLGetActivityLastupdate);