Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getDailySteps returns empty array #326

Open
gibmax opened this issue Nov 7, 2022 · 3 comments
Open

getDailySteps returns empty array #326

gibmax opened this issue Nov 7, 2022 · 3 comments

Comments

@gibmax
Copy link

gibmax commented Nov 7, 2022

Hello guys, I am trying to get daily steps data from my google fit app. I can see the steps data in the app but getDailySteps() is returning an empty array. I am using "react": "18.1.0", "react-native": "0.70.4", "react-native-google-fit": "^0.19.0".

Below is my code:

const getDailySteps = () => {
    GoogleFit.getDailySteps("2022-11-02T10:38:48.611Z")
      .then((res) => {
        console.log('getDailySteps >>> ', res);
      })
      .catch((err) => {console.warn(err)});
  }
  
const handleAuthorize = () => {
  const options = {
    scopes: [
      Scopes.FITNESS_ACTIVITY_READ,
      Scopes.FITNESS_ACTIVITY_WRITE,
      Scopes.FITNESS_LOCATION_READ,
      Scopes.FITNESS_LOCATION_WRITE
    ]
  }    
  GoogleFit.authorize(options)
    .then(authResult => {
      if (authResult.success) {
        console.log("AUTH_SUCCESS");
        getDailySteps();
      } else {
        console.log("AUTH_DENIED - " + authResult.message);
      }
    })
    .catch(() => {
      console.log("AUTH_ERROR");
    });
}
handleAuthorize();

AndoridManifest.xml:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<uses-sdk android:targetSdkVersion="22" />

<queries><package android:name="com.google.android.apps.fitness" /></queries>

settings.gradle:

include ':react-native-google-fit'
project(':react-native-google-fit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-fit/android')

Here is the console.log output:

getDailySteps >>>  
[{"rawSteps": [], "source": "com.google.android.gms:merge_step_deltas", "steps": []}, 
{"rawSteps": [], "source": "com.xiaomi.hm.health", "steps": []}, 
{"rawSteps": [], "source": "com.google.android.gms:estimated_steps", "steps": []}]

Please help. Thanks!

@krisidmisso
Copy link

@gibmax did you find a solution for this?

@gibmax
Copy link
Author

gibmax commented May 10, 2023

@krisidmisso No, I wasn't able to resolve this issue

@shivamlooper
Copy link

shivamlooper commented Oct 30, 2023

Try disconnect and reconnect it will work

If your steps are zero then run something like this

export const reAuth = async () => {
  return new Promise(async (resolve, reject) => {
    if (GoogleFit.isAuthorized) {
      GoogleFit.disconnect();
      GoogleFit.checkIsAuthorized().then(async () => {
        await GoogleFit.authorize(options);
        return resolve(GoogleFit.isAuthorized);
      });
    } else {
      await GoogleFit.authorize(options);
      resolve(GoogleFit.isAuthorized);
    }
  });
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants