OvalMoney / react-native-fitness

A React Native module to interact with Apple Healthkit and Google Fit.
MIT License
341 stars 68 forks source link

[Android] Application needs OAuth consent from the user #96

Open NguyenHoangMinhkkkk opened 3 years ago

NguyenHoangMinhkkkk commented 3 years ago

This Error happen with getHeartRate method while the othes methods are working fine after sign in and allow permissions (permission HeartRate included).


const permissions = [ { kind: Fitness.PermissionKinds.Steps, access: Fitness.PermissionAccesses.Read, }, { kind: Fitness.PermissionKinds.Calories, access: Fitness.PermissionAccesses.Read, }, { kind: Fitness.PermissionKinds.Distances, access: Fitness.PermissionAccesses.Read, }, { kind: Fitness.PermissionKinds.HeartRate, access: Fitness.PermissionAccesses.Read, }, ];


let currentDate = new Date(); let start = new Date(2021, 1, 1, 0, 0, 0); let end = new Date( currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate(), 23, 59, 59,);

const getHeartRate = () => { Fitness.getHeartRate({ startDate: start, endDate: end, interval: 'days' }) .then((res) => { console.log('getHeartRate', res); }) .catch((e) => { console.log('error', e); }); };


Screen Shot 2021-02-26 at 16 09 13 Screen Shot 2021-02-26 at 16 48 51 Screen Shot 2021-02-26 at 16 59 23

robrechtme commented 2 years ago

I had the same issue, I think the error message you receive from the Google Fit API is incorrect.

For heart rate you also need to request the android.permission.BODY_SENSORS permission. You can do so by using react-native-permissions.