I am developing an android application, which uses Google Speech to text via the Google cloud streaming Speech API at the moment, however I am having trouble to get the authentication to work.
I want to authenticate at the Google Cloud API using OAuth2 and a authkey.json from a Google Service account.
I use the SpeechGrpc.SpeechStub
class from package google.cloud.speech.v1beta1
to call RPC methods. This needs a ManagedChannel
in the constructor through which it communicates with the API.
I found an example showing how to create a ManagedChannel
with GoogleCrendential
here: GoogleCloudPlatform/java-docs-samples
It worked until the point of intercepting the credentials into the channel. The ClientAuthInterceptor
class, which is used in the example to intercept the credentials into the channel is
- deprecated
- takes only
com.google.auth.Credentials
as argument whileGoogleCredential
inherits fromcom.google.api.client.auth.oauth2.Credential
.
Next try: google example: Using OAuth 2.0 with the Google API Client Library for Java
It advises me to use a Plus
to wrap the GoogleCrendential
.
But the Plus
is also deprecated
and does not even contain
either a method
builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(), credential)
as shown in topic GoogleCredential on that page, nor a method
Plus.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(APPLICATION_NAME).build();
As shown in section ServiceAccounts on that page.
I am running out of options as the SpeechGrpc.SpeechStub
class, which is used to call rpc methods, needs a ManagedChannel
to work.
An other option could maybe be to add the credentials to the SpeechGrpc.SpeechStub
and not to the ManagedChannel
through the method
SpeechGrpc.newStub(channel).withCallCredentials(CallCredentials creds)
If this is possible, I would like to know, how I can create CallCredentials
out of a Service Account's authkey.json
file.
I read through every example, google documentation and thread on this topic I could find within the last weeks, but I don't get this authentication to work.
I hope anyone in here now can help me out of this confusing google api and library issue.