Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    sykenrussel
    @sykenrussel
    Hi I tried doing the npm install as well as import GoogleFit, { Scopes } from 'react-native-google-fit'; but the authorization is still false
    sykenrussel
    @sykenrussel
    @aboveyunhai

    const opt = {
    startDate: "2017-01-01T00:00:17.971Z", // required ISO8601Timestamp
    endDate: new Date().toISOString(), // required ISO8601Timestamp
    bucketUnit: "DAY", // optional - default "DAY". Valid values: "NANOSECOND" | "MICROSECOND" | "MILLISECOND" | "SECOND" | "MINUTE" | "HOUR" | "DAY"
    bucketInterval: 1, // optional - default 1.
    };
    async function fetchData() {
    const res = await GoogleFit.getDailyStepCountSamples(opt);
    console.log(res);
    }
    fetchData();

    This is my simple code but I get attempt to invoke virtual method. I tried looking at this git thread: StasDoskalenko/react-native-google-fit#20 but it doesnt mention how to fix it even with authorization.

    aboveyunhai
    @aboveyunhai
    @sykenrussel My best guess it to try to safely wrap your function inside Auth check. Individual call without auth check can fail or be interrupted under any circumstances.
    const auth = await GoogleFit.authorize(options);
    if (auth.success or auth) {
     call your function here
    }
    sykenrussel
    @sykenrussel
    @aboveyunhai thanks that works now! Would have been better if that was mentioned in the documentation haha
    image.png
    @aboveyunhai is it also normal that the output is like this?
    [{"activityName": "unknown", "device": "", "end": 1636331399095, "sourceId": "", "sourceName": "", "start": 1483228817971, "tracked": true}] [{"rawSteps": [], "source": "com.google.android.gms:estimated_steps", "steps": []}, {"rawSteps": [], "source": "com.google.android.gms:merge_step_deltas", "steps": []}, {"rawSteps": [], "source": "com.xiaomi.hm.health", "steps": []}]
    I am using android virtual emulator so would that be a possible cause?
    sykenrussel
    @sykenrussel
    I also get empty arrays even if I had set the options to minutes and the intervals to 15 as was mentioned here: StasDoskalenko/react-native-google-fit#207
    aboveyunhai
    @aboveyunhai
    @sykenrussel it's expected the result you would get. You need to try it in real device to record at least some data. Existing data that aren't from your app wouldn't be caught ussually
    sykenrussel
    @sykenrussel
    Ohhh dang what about the output just being []?
    image.png
    1 reply
    aboveyunhai
    @aboveyunhai
    @sykenrussel it means you currently had no data. If you don't have or record data by this app. What do you expect? By default it wouldn't read data recorded by other app.
    sykenrussel
    @sykenrussel
    Does it get the data from my google fit account then?
    sykenrussel
    @sykenrussel
    image.png
    Hi my step results are all object is there something wrong with it?
    Sean Noxious
    @SeanNoxious_twitter

    Hey, So i keep getting a similar issue as other folks.

    My code looks like

      async authorize() {
        // The list of available scopes inside of src/scopes.js file
        const options = {
          scopes: [
            Scopes.FITNESS_ACTIVITY_READ,
            Scopes.FITNESS_ACTIVITY_WRITE,
            Scopes.FITNESS_BODY_READ,
            Scopes.FITNESS_BODY_WRITE,
            Scopes.FITNESS_LOCATION_READ,
            Scopes.FITNESS_LOCATION_WRITE
          ]
        };
    
        const authResult = await GoogleFit.authorize(options);
        return !!authResult?.success;
      }

    and i've gone through the instructions located here:
    https://github.com/StasDoskalenko/react-native-google-fit/blob/master/docs/INSTALLATION.md#demo-walkthrough

    I'm on react-native "react-native": "^0.66.3", in my package.json
    So I only went through the Demo Walkthrough (Development Setup)

    but whenever i run the authorize function i see this error.

    caught error TypeError: Cannot read property 'isAuthorized' of undefined
        at _callee2$ (index.android.js:62)
        at tryCatch (runtime.js:63)
        at Generator.invoke [as _invoke] (runtime.js:294)
        at Generator.next (runtime.js:119)
        at tryCatch (runtime.js:63)
        at invoke (runtime.js:155)
        at runtime.js:190
        at tryCallTwo (core.js:45)
        at doResolve (core.js:200)
        at new Promise (core.js:66)

    And i tracked it down to this code file

    react-native-google-fit/index.android.js

    Specifcally line #19:
    const googleFit = NativeModules.RNGoogleFit

    NativeModules doesn't seem to have a module for RNGoogleFit

    Is there something else i can try?

    aboveyunhai
    @aboveyunhai
    @SeanNoxious_twitter Never trust the GoogleFit.isAuthorized. It's quite misleading, I guess I will need to remove it at some point. It's a legacy implementation. It probably used to work in the past. It's not persisted in storage after you close your app or something happen during the app.
    Instead, use your authorize() to guard through all your google fit call. It wouldn't cause duplicated login. It seems like google fit api auto handle the auth process even though you called multiple times.
    const success =  await authorize();
    if (success) { 
    //call your function here 
    }
    Sean Noxious
    @SeanNoxious_twitter
    I believe i have tried this and it's still not working but let me give it a go and I'll let you know.
    Sean Noxious
    @SeanNoxious_twitter
    image.png

    Hey @aboveyunhai

    I've changed my code to the following.

     async authorize() {
        // The list of available scopes inside of src/scopes.js file
        const options = {
          scopes: [
            Scopes.FITNESS_ACTIVITY_READ,
            Scopes.FITNESS_ACTIVITY_WRITE,
            Scopes.FITNESS_BODY_READ,
            Scopes.FITNESS_BODY_WRITE,
            Scopes.FITNESS_LOCATION_READ,
            Scopes.FITNESS_LOCATION_WRITE
          ]
        };
    
        let authResult;
        try { 
          authResult = await GoogleFit.authorize(options);
        } catch (err) {
          console.error(err);
          throw err;
        }
        return !!authResult?.success;

    and i still receive the following error.

    caught error TypeError: Cannot read property 'isAuthorized' of undefined
        at _callee2$ (index.android.js:62)
        at tryCatch (runtime.js:63)
        at Generator.invoke [as _invoke] (runtime.js:294)
        at Generator.next (runtime.js:119)
        at tryCatch (runtime.js:63)
        at invoke (runtime.js:155)
        at runtime.js:190
        at tryCallTwo (core.js:45)
        at doResolve (core.js:200)
        at new Promise (core.js:66)

    I'm not directly referencing the isAuthorized property in my code.

    image.png
    Sean Noxious
    @SeanNoxious_twitter
    Sorry to be a bother but not really able to make any progress here. Anyone have any suggestions?
    sykenrussel
    @sykenrussel
    As much as I'd like to help you I think google made some changes that make this RN package difficult to work with
    Sean Noxious
    @SeanNoxious_twitter
    i ended up just using some old code i found on github randomly.
    Soham
    @shmkane
    @sykenrussel what changes in Google? And what exactly are the effects in the rn package?
    sykenrussel
    @sykenrussel
    well firstly it returns an object when i call in steps
    image.png
    How do I get that output? I tried using bucketUnit: BucketUnit.Minute and interval at 15 but I keep getting aggregated results
    image.png
    sykenrussel
    @sykenrussel
    I cant seem to choose the estimated as the datasource
    aboveyunhai
    @aboveyunhai

    you cant really choose the source, source just indicates the where the data comes from.
    it could come from some legacy code, and Google Fit store can't really tell you the true source once multiple data source existed in the same time span. You should rely on the data itself instead of text description.
    As far as I know, those description can be customized by implementation if you truly want to.

    For production usage, a well craft app should store customize user data by themselves and let google fit do all the fitness data work, of cuz, under whatever Google Fit Data guideline if the data involved some data policies.

    sykenrussel
    @sykenrussel
    I see. Is it possible to get minute by minute workout data?
    14 replies
    image.png
    Like that is the options I used but it still returns it as aggregate
    Screenshot_20211130-130819.jpg
    Like I want to get those data, but using the package it just aggregates it
    sykenrussel
    @sykenrussel
    image.png
    image.png
    sumitmaurya1
    @sumitmaurya1
    sds
    I am getting scopes issue while working with react-native-google-fit
    ======================= error ============================
    error: cannot find symbol
    GoogleSignInAccount gsa = GoogleSignIn.getAccountForScopes(mReactContext, new Scope(Scopes.FITNESS_ACTIVITY_READ));
    ^
    symbol: variable FITNESS_ACTIVITY_READ
    location: class com.google.android.gms.common.Scopes
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    aboveyunhai
    @aboveyunhai
    Read the discussion here for scope issue: StasDoskalenko/react-native-google-fit#268
    lucapaciello-tech4care
    @lucapaciello-tech4care
    hi. I have a question: does this library works for ios too?
    1 reply
    Osh
    @OshedheMunasinghe

    I need help.
    So I have fixed without Expo and sure it is working sucess after auth with RN-Cli. But!
    I don't understand how to get sampels from steps
    Why I get error dates and adjustment
    and also other error like com.reactnative.googlefit.StepHistory, com.reactnative.googlefit.GoogleFitManager.getSTepHistory()

    I went to check example
    but there are no demo examples how to get steps ...

    So here is mine

    /**  
     * Sample React Native App * https://github.com/facebook/react-native * * @format  
      * @flow strict-local  
     */  
    import type { Node } from "react";  
    import React, { useEffect } from "react";  
    import GoogleFit, { BucketUnit, Scopes } from "react-native-google-fit";  
    import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View } from "react-native";  
    
    import {  
      Colors,  
      DebugInstructions,  
      Header,  
      LearnMoreLinks,  
      ReloadInstructions,  
    } from "react-native/Libraries/NewAppScreen";  
    
    const Section = ({ children, title }): Node => {  
      const isDarkMode = useColorScheme() === "dark";  
     return (  
        <View style={styles.sectionContainer}>  
     <Text  style={[  
              styles.sectionTitle,  
      {  
                color: isDarkMode ? Colors.white : Colors.black,  
      },  
      ]}>  
      {title}  
          </Text>  
     <Text  style={[  
              styles.sectionDescription,  
      {  
                color: isDarkMode ? Colors.light : Colors.dark,  
      },  
      ]}>  
      {children}  
          </Text>  
     </View>  );  
    };  
    
    const App = () => {  
      const isDarkMode = useColorScheme() === "dark";  
    
     const backgroundStyle = {  
        backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,  
      };  
      useEffect(() => {  
    
        const options = {  
          scopes: [  
            Scopes.FITNESS_ACTIVITY_READ,  
      Scopes.FITNESS_ACTIVITY_WRITE,  
      Scopes.FITNESS_BODY_READ,  
      Scopes.FITNESS_BODY_WRITE,  
      ],  
      };  
      GoogleFit.authorize(options)  
          .then(authResult => {  
            if (authResult.success) {  
              console.log("AUTH SUCESS");  
      } else {  
              console.error("AUTH DENIED", authResult);  
      }  
          })  
          .catch(() => {  
            console.log("AUTH_ERROR");  
      });  
      });  
    
      GoogleFit.startRecording((callback) => {  
        // Process data from Google Fit Recording API (no google fit app needed)  
      });  
    
     const opt = {  
        startDate: "2017-01-01T00:00:17.971Z", // required ISO8601Timestamp  
      endDate: new Date().toISOString(), // required ISO8601Timestamp  
      bucketUnit: BucketUnit.DAY, // optional - default "DAY". Valid values: "NANOSECOND" | "MICROSECOND" | "MILLISECOND" | "SECOND" | "MINUTE" | "HOUR" | "DAY"  
      bucketInterval: 1, // optional - default 1.  
      };  
    
      GoogleFit.getDailyStepCountSamples(opt)  
        .then((res) => {  
          console.log('Daily steps >>> ', res)  
        })  
        .catch((err) => {console.warn(err)});  
    
    // or with async/await syntax  
      async function fetchData() {  
        const res = await GoogleFit.getDailyStepCountSamples(opt)  
      console.log(res);  
      }  
    
    // shortcut functions,  
    // return weekly or daily steps of given date  
    // all params are optional, using new Date() without given date,  
    // adjustment is 0 by default, determine the first day of week, 0 == Sunday, 1==Monday, etc.  
      GoogleFit.getDailySteps(date).then().catch()  
      GoogleFit.getWeeklySteps(date, adjustment).then().catch()  
    
    
      return (  
        <SafeAreaView style={backgroundStyle}>  
     <StatusBar barStyle={isDarkMode ? "light-content" : "dark-content"} />  
     <ScrollView  contentInsetAdjustmentBehavior="automatic"  
      style={backgroundStyle}>  
     <Header /> <View  style={{  
                backgroundColor: isDarkMode ? Colors.black
    Douglas-Hsieh
    @Douglas-Hsieh
    Hey, thanks for the package! It looks like there aren't methods for getting Heart Points, Step Count Cadence. Any plans to support those?
    Phước Thiện Đỗ
    @twins23:matrix.org
    [m]
    @aboveyunhai: Hi my boy
    I need some help!🤕
    Phước Thiện Đỗ
    @twins23:matrix.org
    [m]
    I ran app on real device by USB