fitbitter icon indicating copy to clipboard operation
fitbitter copied to clipboard

Is it possible to show daily 24hours activity data?

Open samlim96 opened this issue 1 year ago • 4 comments

Such as the start time and end time of the steps or moving distance

samlim96 avatar Oct 07 '23 16:10 samlim96

I'm using this library and unfortunately it doesn't offer intraday calls, I suggest you look at this link: https://dev.fitbit.com/build/reference/web-api/intraday/get-activity-intraday-by-interval

In addition, intraday calls can only be made within a maximum range of 24 hours and only after approval via a request via the fitbit form. https://dev.fitbit.com/build/reference/web-api/intraday/

LorisTrainect avatar Oct 24 '23 14:10 LorisTrainect

Hi everyone, sorry for being disappeared. I will restart maintaining the repo in the very next future. Anyway, as pointed out by @LorisTrainect, since you need to request Fitbit approval for issuing intraday calls, I did not include these API into Fitbitter. If you think this is an important feature to have, I can implement those calls. What's your opinion?

gcappon avatar Oct 25 '23 09:10 gcappon

I needed them and implemented them myself using your library. Everything is working for me, of course if it were included it would be more convenient. I had to gear up a bit to handle the fact that the token expired after 8 hours, in the previous version the library handled that.

I commented out line 36 ( getResponse() --> // await _checkAccessToken(fitbitUrl); ) of the fitbitDataManager as it is no longer needed as I need to save the credentials returned by that function somewhere on my own.

I can share the code with you no problem in any case, in my specific case I ask for 1m details but you can add a parameter

  static FitbitActivityTimeseriesAPIURL _dateTimeRangeWithResource({required FitbitCredentials fitbitCredentials,
    required DateTime day,
    required DateTime endTime,
    required Resource resource}) {

    String startDateStr = onlyDayDateFormatTicks.format(day);
    String endDateStr = onlyDayDateFormatTicks.format(day);

    String startTimeStr = onlyTimeNoSecondsAMPM.format(day);
    String endTimeStr = onlyTimeNoSecondsAMPM.format(endTime);

    return FitbitActivityTimeseriesAPIURL(
      url:
      'https://api.fitbit.com/1/user/${fitbitCredentials.userID}/activities/${resourceToString[resource]}/date/$startDateStr/$endDateStr/1min/time/$startTimeStr/$endTimeStr.json',
      resourceString: resourceToString[resource]!,
      fitbitCredentials: fitbitCredentials,
    );

  }

How I used it with this library:

double value = 0;

  FitbitActivityTimeseriesDataManager fitbitActivityTimeseriesDataManager = FitbitActivityTimeseriesDataManager(
    clientID: clientID,
    clientSecret: clientSecret,
  );

List<FitbitActivityTimeseriesData> data = [];

  data = await fitbitActivityTimeseriesDataManager
      .fetch(
      _dateTimeRangeWithResource(
          fitbitCredentials: credentials!,
          day: dateStart,
          endTime: now,
          resource: resource
      )
  ) as List<FitbitActivityTimeseriesData>;

 for (FitbitActivityTimeseriesData d in data) {
  value +=d.value ?? 0;
}

For my problem this solution works, however it is useless if you need to take values from individual datasets.

LorisTrainect avatar Oct 25 '23 10:10 LorisTrainect

Hi everyone, sorry for being disappeared. I will restart maintaining the repo in the very next future. Anyway, as pointed out by @LorisTrainect, since you need to request Fitbit approval for issuing intraday calls, I did not include these API into Fitbitter. If you think this is an important feature to have, I can implement those calls. What's your opinion?

100% yes!! Kindly please implement it, it would be a very useful feature 🙇🏻‍♂️

samlim96 avatar Oct 27 '23 12:10 samlim96