react-native-google-fit icon indicating copy to clipboard operation
react-native-google-fit copied to clipboard

Data for users who never used Google Fit

Open kaishuvam7 opened this issue 3 years ago • 3 comments

This library has worked very well for us - so thank you again!

We're trying to make this work now for users who don't want to download Google Fit (which seems to be required to use our app). We've noticed people who used to have the Fit app, but have uninstalled, are getting their data correctly. A new Google account, in comparison, is getting no data.

We've looked at and implemented most suggestions such as this helpful one, but nothing works for this specific case.

What could we be doing wrong? Do we have to write and then read the required data, or something else entirely?

Our scopes:

Scopes.FITNESS_ACTIVITY_READ,
Scopes.FITNESS_HEART_RATE_READ,
Scopes.FITNESS_LOCATION_READ,

Obtaining data:

static getFitnessData = async ({
    startDate,
    endDate,
    isSession = true,
    check = true,
  } = {}) => {
    console.log("getData>>>>");
    try {
      const fitnessFetchStart = moment();
      if (check) {
        const isFitnessAllowed = await Utils.getFitnessPermission();
        if (!isFitnessAllowed) return;
      }
      const interval = "hour";
      const bucketInterval = 1;
      var start = startDate.format(fitnessDateFormat);
      var end = endDate.format(fitnessDateFormat);
      // console.log({ startDate: start, endDate: end });
      const stps =
        Platform.OS === "android"
          ? await GoogleFit.getDailyStepCountSamples({
              startDate: startDate,
              endDate: endDate,
              bucketInterval,
            })
              .then((res) => {
                // console.log(
                //   "Daily steps >>>123123>>>>>",
                //   JSON.stringify(res[res.length - 1].steps)
                // );
                return res[res.length - 1]?.steps || [];
              })
              .catch((err) => {
                console.warn(err);
              })
          : await Fitness.getSteps({
              startDate: startDate,
              endDate: endDate,
              interval,
            });
      const cals =
        Platform.OS === "android"
          ? await GoogleFit.getDailyCalorieSamples({
              startDate: startDate,
              endDate: endDate,
              bucketInterval,
            })
              .then((res) => {
                // console.log("Daily cals >>> ", res);
                return res;
              })
              .catch((err) => {
                console.warn(err);
              })
          : await Fitness.getCalories({
              startDate: startDate,
              endDate: endDate,
              interval,
            });

      const dist =
        Platform.OS === "android"
          ? await GoogleFit.getDailyDistanceSamples({
              startDate: startDate,
              endDate: endDate,
              bucketInterval,
            })
              .then((res) => {
                // console.log("Daily Distance >>> ", res);
                return res;
              })
              .catch((err) => {
                console.warn(err);
              })
          : await Fitness.getDistances({
              startDate: startDate,
              endDate: endDate,
              interval,
            });

kaishuvam7 avatar Dec 07 '22 15:12 kaishuvam7

Did you find some solution to this?

shmkane avatar Feb 21 '24 17:02 shmkane

@kaishuvam7 Did you end up coming with a solution for this?

ninjz avatar Apr 21 '24 16:04 ninjz

No - we were unable to. Thankfully, this segment of users proved to be small enough for it to not be a major worry.

kaishuvam7 avatar Apr 22 '24 07:04 kaishuvam7