gcappon / fitbitter

A Flutter package to make your life easier when dealing with Fitbit APIs.
https://gcappon.github.io/fitbitter/
BSD 3-Clause "New" or "Revised" License
19 stars 21 forks source link

Is it possible to show daily 24hours activity data? #20

Open samlim96 opened 1 year ago

samlim96 commented 1 year ago

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

LorisTrainect commented 1 year ago

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/

gcappon commented 1 year ago

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?

LorisTrainect commented 1 year ago

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.

samlim96 commented 1 year ago

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 🙇🏻‍♂️