Ansal
Ansal

Reputation: 11

Google Fit APi for step count is giving permission denied for first time user

i have developed an app which sync user step count from google fit. I have observed that users who are syncing as soon as the installation of google fit app in there mobile and user who haven't installed the app are getting the following error

{ "error": { "code": 403, "message": "datasource not found or not readable: derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", "errors": [ { "message": "datasource not found or not readable: derived:com.google.step_count.delta:com.google.android.gms:estimated_steps", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } }

When they reinstall the app it works fine

If they sync next day it will work

here is the code:

const timeGap = {
    endTimeMillis: new Date().getTime() + 1 * 60 * 60 * 1000,
    startTimeMillis: new Date('2021-01-01 00:00').getTime(),
};
return gapi.client.fitness.users.dataset
  .aggregate({
    userId: 'me',
    resource: {
      aggregateBy: [
        {
          dataTypeName: 'com.google.step_count.delta',
          dataSourceId:
            'derived:com.google.step_count.delta:com.google.android.gms:estimated_steps',
        },
      ],
      endTimeMillis: timeGap.endTimeMillis,
      startTimeMillis: timeGap.startTimeMillis,
      bucketByTime: {
        durationMillis: 86400000,
      },
    },
  })
  .then(
    (response) => {
      console.log('[[[[[', response);
      const stepVals = [];

      console.log(response);
      observer.next(response.result);
      observer.complete();
    },
    (err: any) => {
      observer.error(err);
      observer.next(err);

      // console.error("ERRRR", err);
      observer.complete();
    }
  );

Upvotes: 1

Views: 755

Answers (1)

Graeme Morgan
Graeme Morgan

Reputation: 129

datasource not found ...

The DataSource you're trying to read won't exist until the user has synced data up to the server.

This error is reasonable to interpret as NOT_FOUND.

Upvotes: 1

Related Questions