OvalMoney / react-native-fitness

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

error: null reference. when I do console.log, isAuthorized always return false, PermissionAccess.write always return undefined #63

Closed philipusmartin9 closed 4 years ago

philipusmartin9 commented 4 years ago

Hello,

First of all, great work! Im so excited to try this plugin. I tried using this with RN 0.62, (using autolinking). if I run without checking isAuthorized, it always gives null reference error. So, I put some console.log(s) and found out isAuthorized always return false, PermissionAccess.write always return undefined. Did I miss a step in setting up this plugin, or maybe there's missing step in the usage?

Thanks in advance, pardon if the snippet is a bit messy

const permissions = [ { kind: Fitness.PermissionKind.Step, access: Fitness.PermissionAccess.Write } ];

`const logSteps = async () => {

console.log("permission:", permissions); // the result is {access: undefined, kind: 0}
Fitness.isAuthorized(permissions)
  .then(async (authorized) => {
    let initialDate = new Date();
    let startDate = new Date(initialDate.getFullYear(), initialDate.getMonth(), initialDate.getDate(), 0, 0, 0);
    let endDate = new Date(initialDate.getFullYear(), initialDate.getMonth(), initialDate.getDate(), 23, 59, 59);
    let formattedStart = startDate.toISOString();
    let formattedEnd = endDate.toISOString();
    console.log('start:', formattedStart);
    console.log('end:', formattedEnd);
    // Do something
    console.log('auth result:', authorized); // always return false
    if(authorized){
      let result = await Fitness.getSteps({
        startDate: formattedStart,
        endDate: formattedEnd,
        interval: 'days'
      });
    }
  })
  .catch((error) => {
    // Do something
    console.log('Failed auth', error);
  });

} `

philipusmartin9 commented 4 years ago

I finally managed to make it work by adding this to my build.gradle dependencies:

implementation "com.google.android.gms:play-services-base:+" implementation "com.google.android.gms:play-services-auth:+" implementation "com.google.android.gms:play-services-fitness:+"

the permission request works, now the authorization returns true, but I still only get empty array even though I have steps data in my google fit account. could anyone please help with this? thanks

philipusmartin9 commented 4 years ago

It works, the app can only get the google fit data in the same, not cross-device.

Francesco-Voto commented 4 years ago

@philipusmartin9 Thank you for explain the issue. Glad to hear it works in some way