I develop my App on Android studio on a Macbook. Trying to use Google Translate API I keep on getting "The request is missing a valid API key".
I have created a Service Account for my app on GCP, created a key and downloaded it to my Macbook.
My ~/.bash_profile is:
eval $(/usr/libexec/path_helper -s) PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
export GOOGLE_APPLICATION_CREDENTIALS=vigilant-sunup-233615-64a91c3335bb.json
The echo looks good also:
Brian-MacBook-Pro:~ Brian$ echo $GOOGLE_APPLICATION_CREDENTIALS vigilant-sunup-233615-64a91c3335bb.json
The concerned code is:
protected String doInBackground(String... params)
{
String text = params[0]; //text to translate
String sourceLang = "en"; // source Language
String targetLang = "fr"; // target Language
String translated = "";
try
{
//update UI
Translate translate = TranslateOptions.getDefaultInstance().getService();
Translation translation =
translate.translate(
text,
Translate.TranslateOption.sourceLanguage(sourceLang),
Translate.TranslateOption.targetLanguage(targetLang));
translated = translation.getTranslatedText();
} catch (Exception e) {
e.printStackTrace();
}
I keep on getting "The request is missing a valid API key" when it reaches the statement:
Translation translation =
translate.translate(
text,
Translate.TranslateOption.sourceLanguage(sourceLang),
Translate.TranslateOption.targetLanguage(targetLang));
Any help ?
Thank you.