react-native-google-fit
react-native-google-fit copied to clipboard
getDailySteps returns empty array
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!
@gibmax did you find a solution for this?
@krisidmisso No, I wasn't able to resolve this issue
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);
}
});
};