Я хочу использовать Google Translation API с ограниченным ключом, но всегда появляется сообщение об ошибке
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Requests from this Android client application <empty> are blocked.",
"reason" : "rateLimitExceeded"
} ],
"message" : "Requests from this Android client application <empty> are blocked.",
"status" : "PERMISSION_DENIED"
}
Если я снимаю ограничения для ключа API, это работает.
TranslateOptions options = TranslateOptions.newBuilder()
.setApiKey(API_KEY)
.build();
Translate translate = options.getService();
translateLang = Preference.getTranslatorLanguage(MainActivity.this);
final Translation translation =
translate.translate( str ,
Translate.TranslateOption.targetLanguage(translateLang));
textViewHandler.post(new Runnable() {
@Override
public void run()
{
if (textView != null) {
textView.setText(translation.getTranslatedText());
}
}
});
return null;
// This is the full error code
2019-10-11 17:15:22.114 27720-27754/com.example.googletranslate E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: com.example.googletranslate, PID: 27720
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:354)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
at java.util.concurrent.FutureTask.run(FutureTask.java:271)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.google.cloud.translate.TranslateException: Requests from this Android client application <empty> are blocked.
at com.google.cloud.translate.spi.DefaultTranslateRpc.translate(DefaultTranslateRpc.java:56)
at com.google.cloud.translate.spi.DefaultTranslateRpc.translate(DefaultTranslateRpc.java:110)
at com.google.cloud.translate.TranslateImpl$4.call(TranslateImpl.java:113)
at com.google.cloud.translate.TranslateImpl$4.call(TranslateImpl.java:110)
at com.google.cloud.RetryHelper.doRetry(RetryHelper.java:179)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:244)
at com.google.cloud.translate.TranslateImpl.translate(TranslateImpl.java:110)
at com.google.cloud.translate.TranslateImpl.translate(TranslateImpl.java:124)
at com.ajaymourya.googletranslate.MainActivity$AsyncCaller.doInBackground(MainActivity.java:198)
at com.ajaymourya.googletranslate.MainActivity$AsyncCaller.doInBackground(MainActivity.java:163)
at android.os.AsyncTask$2.call(AsyncTask.java:333)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:764)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Requests from this Android client application <empty> are blocked.",
"reason" : "rateLimitExceeded"
} ],
"message" : "Requests from this Android client application <empty> are blocked.",
"status" : "PERMISSION_DENIED"
}
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
at com.google.cloud.translate.spi.DefaultTranslateRpc.translate(DefaultTranslateRpc.java:91)
... 14 more