0

I am trying to retrieve Heart Bit data for a certain time range. I am breaking up a time range into several smaller time ranges for example each one day long. So, if I requested data for the last 5 days it would provide 5-time ranges. All that data about time ranges is stored in the GoogleFitReadRequestData List.

public class GoogleFitReadRequestData {
    private DataType dataType;
    private long startTime;
    private long endTime;

    public GoogleFitReadRequestData(DataType dataType, long startTime, long endTime) {
        this.dataType = dataType;
        this.startTime = startTime;
        this.endTime = endTime;
    } 
}

I then create requests in a loop for those data ranges. This is a simplified example of what my application does.

public void stackOverflowRequestExample() {
    initContext();
    HistoricalClientHelper clientHelper = new HistoricalClientHelper();
    List<GoogleFitReadRequestData> readRequestData = new ArrayList<>();
    readRequestData.addAll(clientHelper.GetTimeBuckets(DataType.TYPE_HEART_RATE_BPM));

    for (GoogleFitReadRequestData requestData : readRequestData) {
        DataReadRequest.Builder readRequestBuilder = new DataReadRequest.Builder();
        readRequestBuilder.read(requestData.getDataType());
        readRequestBuilder.enableServerQueries();
        readRequestBuilder.setTimeRange(requestData.getStartTime(), requestData.getEndTime(), TimeUnit.MILLISECONDS);

        GoogleSignInAccount googleSignInAccount =
                GoogleSignIn.getAccountForExtension(this.appContext, getFitnessOptions(requestData.getDataType()));

        Fitness.getHistoryClient(this.appContext, googleSignInAccount)
                .readData(readRequestBuilder.build())
                .addOnSuccessListener(response -> {
                    clientHelper.ProcessDataSetList(response.getDataSets());
                })
                .addOnCanceledListener(() -> Log.w("Google Fit: ", "Reading request from Google Fit was cancelled"))
                .addOnFailureListener(e -> Log.w("Google Fit: ", "There was an error reading data from Google Fit", e));
    }
}

public static GoogleSignInOptionsExtension getFitnessOptions(DataType type) {
    FitnessOptions.Builder optionsBuilder = FitnessOptions.builder();
    optionsBuilder.addDataType(type, FitnessOptions.ACCESS_READ);
    return optionsBuilder.build();
}

The problem is that some of them return a response (success), while others do not return any response. Not even canceled or failed. Does anyone know what I am doing wrong?

PS: I noticed this issue only with the TYPE_HEART_RATE_BPM data type. Others, like TYPE_STEP_COUNT_DELTA work just fine.

1 Answers1

0

Ok. Turns out the problem was with how the permissions for reading were set up in the Google Cloud Console. In the OAuth consent screen, scopes had to be manually found in Google Fitbit documentation and added as complete links and only then they appeared in the sensitive scopes section.