cph-cachet / flutter-plugins

A collection of Flutter plugins developed by CACHET
528 stars 627 forks source link

HEALTH 8.0.0 Quota Limit Exceeded #787

Open Kam5678 opened 10 months ago

Kam5678 commented 10 months ago

So currently I am running into the following issue for android whenever I try to fetch health data(Steps, HeartRate, Sleep_Session, Sleep_Awake)

E/AndroidRuntime(13306): android.os.RemoteException: Request rejected. Rate limited request quota has been exceeded. Please wait until quota has replenished before making further requests.
E/AndroidRuntime(13306):    at androidx.health.platform.client.impl.error.ErrorStatusConverterKt.toException(ErrorStatusConverter.kt:49)
E/AndroidRuntime(13306):    at androidx.health.platform.client.impl.ReadDataRangeCallback.onError(ReadDataRangeCallback.kt:35)
E/AndroidRuntime(13306):    at androidx.health.platform.client.service.IReadDataRangeCallback$Stub.onTransact(IReadDataRangeCallback.java:75)
E/AndroidRuntime(13306):    at android.os.Binder.execTransactInternal(Binder.java:1195)
E/AndroidRuntime(13306):    at android.os.Binder.execTransact(Binder.java:1159)
E/AndroidRuntime(13306):    Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@a816b6d, Dispatchers.Main]

https://developer.android.com/guide/health-and-fitness/health-connect-guidelines/rate-limiting) I honestly just wanted some guidance because I don't think this problem is related to the package, but more with the amount of API calls I can make when fetching data through healthconnect. But currently using this package I think all I can do is make these API calls to get data(Possible solution would be to minimize calls and save data to a database I think?)

https://developer.android.com/guide/health-and-fitness/health-connect/common-workflows/sync-data#pull-data In order to minmize API calls android suggests using something called changelog handling which utilizes healthConnectClient and a function called getChangesToken(healthConnectClient.getChangesToken(..) to check if there were any changes in data, which I can then use to update my database data whenever there are changes. But I believe currently this health package doesn't support that?

Or honestly if there is any other possible solution you would suggest, since this issue right now causes my whole app to crash whenever I get this error.

Would honestly appreciate any guidance!

maxbeech commented 8 months ago

Bumping this up. Definitely an issue, investigating support for changelog handling like Kam suggested would be hugely appreciated.

My use case: if I'm retrieving a lot of data, I have to do it in batches to avoid variables being too big, but this then triggers this error.

AngryDuckFTW commented 4 months ago

This is definitely a bit problem, my use case is steps and ive had to modify the source of the package in flutter cache to even find the error since it was just been consumed and returning an string just saying cant get steps! since this package only has an interface to pull steps from a from/to range and returning a total, if you want daily by hour thats 24 requests .. so you hit this limit almost instantly, and makes steps pretty much unusable

Kam5678 commented 4 months ago

Yeah, I was able to find a temporary solution for this. Basically what I did was I tried limiting the amount of API calls I made by only making API calls when needed. Each API call allowed 1000 entries in a list, so I would simply keep making these API calls until I recieved back a list that was of length < 1000. Meaning I recieved all needed data from start to end datetimes.

Then simply had to filter the list all at once to get individual date time data.

To go a step further you can then store this data to the database, and then make calls when needed from the last point in your database so that you don't have to make the same API calls everytime.