Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please set your app apiKey #8

Open
Mr-Ramzan opened this issue Oct 18, 2022 · 1 comment
Open

Please set your app apiKey #8

Mr-Ramzan opened this issue Oct 18, 2022 · 1 comment

Comments

@Mr-Ramzan
Copy link

I have Been trying to integrate Realtime text translation API Into my app. I followed the documentation but Upon testing application crashes saying to set the app API key

These are crash logs
Process: com.sotec.translate.app.huawei, PID: 14445
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:321)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.Error: please set your app apiKey
at com.huawei.hms.mlsdk.common.MLApplication.getApiKey(MLApplication.java:412)
at com.huawei.hms.mlsdk.common.MLApplication.getAuthorizationToken(MLApplication.java:381)
at com.huawei.hms.mlsdk.translate.p.j.a(RestClientContext.java:12)
at com.huawei.hms.mlsdk.translate.p.l$b.(RestClientRequestHeaders.java:16)
at com.huawei.hms.mlsdk.translate.p.l$b.(RestClientRequestHeaders.java:1)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.c(MLRemoteTranslator.java:16)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.a(MLRemoteTranslator.java:25)
at com.huawei.hms.mlsdk.translate.cloud.MLRemoteTranslator.syncTranslate(MLRemoteTranslator.java:1)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.callUrlAndParseResult(TranslationUtils.java:72)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.doInBackground(TranslationUtils.java:38)
at com.translate.languagetranslator.freetranslation.network.TranslationUtils.doInBackground(TranslationUtils.java:18)

I have enabled the MLKit service from Console As is mentioned here
.

**Below is the code I Used **

                  `    private String callUrlAndParseResult(String langFrom, String langTo, String word)
        throws Exception {
    // Create a text translator using custom parameter settings.
    MLRemoteTranslateSetting setting = new MLRemoteTranslateSetting
            .Factory()
            // Set the source language code. The BCP-47 standard is used for Traditional Chinese, and the ISO 639-1 standard is used for other languages. This parameter is optional. If this parameter is not set, the system automatically detects the language.
            .setSourceLangCode(langFrom)
            // Set the target language code. The BCP-47 standard is used for Traditional Chinese, and the ISO 639-1 standard is used for other languages.
            .setTargetLangCode(langTo)
            .create();
    MLRemoteTranslator mlRemoteTranslator = MLTranslatorFactory.getInstance().getRemoteTranslator(setting);
    try {
        return mlRemoteTranslator.syncTranslate(word);
        // Processing logic for recognition success.
    } catch (MLException mlException) {
        // Processing logic for detection failure.
        // Obtain the result code. You can process the result code and customize respective messages displayed to users.
        int errorCode = mlException.getErrCode();
        // Obtain the error information. You can quickly locate the fault based on the result code.
      return errorCode+mlException.getMessage();
    }finally {
        if (mlRemoteTranslator!= null) {
            mlRemoteTranslator.stop();
        }
    }
}

`

Please Guide Me what I am Doing Wrong, Because I cannot find any help anywhere else.

@xuxiapu
Copy link

xuxiapu commented Oct 18, 2022

@Mr-Ramzan Thank you for your feedback,You can refer to the official link of setting apikey for details. The link is as follows:https://developer.huawei.com/consumer/en/doc/development/HMS-Plugin-Guides/faq-0000001052151253#section285421445712

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants