I am trying to use Google Cloud Translation API. I have generated API key, but I don't have the .json file where are stored my credentials. Is there any way to put my API key in code so I can use Translation methods, or not? I have found only ways where it is needed to have .json file, but I don't have it. I have found a deprecated method :
Translate translate = TranslateOptions.newBuilder().setApiKey(API_KEY).build().getService();
but it shows me errors:
W/TranslateOptions: Ignoring Application Default Credentials {0}: using explicit setting for API key instead.
W/System.err: java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
W/System.err: at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:134)
Any help would be appreciated!
EDIT: When I put environment variable GOOGLE API KEY and wrote:
Translate translate = TranslateOptions.getDefaultInstance().getService();
Translation translation = translate.translate("¡Hola Mundo!");
I got error on translate.translate() line, it sends request like GET method, not like POST, and that's why it says that it is missing a valid API key, because it is not sending API key at all.
com.google.cloud.translate.TranslateException: The request is missing a valid API key.