GoogleCloudPlatform / android-docs-samples

Apache License 2.0
375 stars 596 forks source link

Capping API usage in case of Speech to Text service (com.google.cloud.speech.v1) #127

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi, I am trying to put an easy mechanism (if it exists on client side, better than a second server) to limit API calls on each client daily. Other Google Cloud services seem to offer this option**. I searched a little in API, I am trying to implement services no top of the nice demo app here

I tried including Firebase Firestores to make a counter on API calls for users, but unfortunately apparently Firestore does not go well with Speech-to-Text in Android, both depending on protobuf java and protofuf javalite which present duplicate dependencies, so I give up Firestore option at all.

I admit, I am taking it step by step as I am not keen Android developer.

Thanks !

**According to documentation:

To identify a user, use the quotaUser=userID parameter. This value is for short term quota enforcement only, so you don't need to use a real user ID. You can choose any arbitrary string under forty characters long that uniquely identifies a user.

The quotaUser parameter is only used for capping requests per user per second. If you don't send the quotaUser parameter, then all calls are attributed to your server machines, in which case calls can't be capped by user.

ghost commented 3 years ago

I managed to use firebase-realtime-database, it's great and easy. Woohoo, not sure it's the best since current needs are just authentication and this API calls counter.

So firebase-realtime-database works well along with speech-to-text dependency, not like Firestore.