Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

android - Implement Google speech credentials with API key or Service accounts

I have a question regarding implementing Google speech, or google cloud API in general, for Android

What I want is to have multiple certificates or API keys for different clients. In practice, I can have 10 different Android devices, linked to Server 1 for Client 1, and 20 different Android devices, linked to another server for Client 2. I would like to split the billing of this clients but using same Android project/package.

In https://github.com/GoogleCloudPlatform/android-docs-samples/tree/master/speech/Speech example there is an OAuth2 Credential used, but the problem here is that you can have only 1 OAuth2 Credential for 1 project, but in this case I would need multiple, so this is not an option.

Even if I implement OAuth2 on a server and refresh Tokens for devices, I would need to have multiples.

In the end I would have 1 google account, with multiple client configuration, where each client is seperate when checking billing info and also for restricting purposes. If I have multiple keys I can just disable one and that is

So my question is (if I can split billing for specific API key/service account, or just know the usage used)

  1. How to change example implementation to use API keys or different Service accounts with GoogleCredentials.fromstream()? Do I need to manually implement API requests to google REST API, or is this possible in Android with something like:

    SpeechClient.create(SpeechSettings.newBuilder().setCredentialsProvider {API_KEY}.build())
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can't have billing details per API Keys used on Speech API. Here, the easiest solution is to have one project per customer. When a request come in, check the user Id (because the user is already authenticated and you have a OAuth2 token) on the server and, according with the user info stored somewhere (we use Firestore for user profile storage), call the Speech API in the correct project.

You have 1 billing per project, and a free tier per project also!


Edit 1

It's possible I wasn't clear. Here a schema.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...