StasDoskalenko / react-native-google-fit

A React Native bridge module for interacting with Google Fit
MIT License
331 stars 210 forks source link

Data for users who never used Google Fit #331

Open kaishuvam7 opened 1 year ago

kaishuvam7 commented 1 year ago

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,
            });
shmkane commented 6 months ago

Did you find some solution to this?

ninjz commented 4 months ago

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

kaishuvam7 commented 4 months ago

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