exception: Token is invalid or expired.
What is this error? I have already set the api key. And what does this token represent?
val setting: MLRemoteTranslateSetting =
MLRemoteTranslateSetting.Factory()
.setSourceLangCode("en")
.setTargetLangCode("hu")
.create()
val mlRemoteTranslator: MLRemoteTranslator =
MLTranslatorFactory.getInstance().getRemoteTranslator(setting)
try {
val result = MLTranslateLanguage.syncGetCloudAllLanguages()
} catch (e: MLException) {
Log.e("ML exception", e.message.toString())
}
var output = ""
try {
output = mlRemoteTranslator.syncTranslate("SOURCE")
} catch (e: MLException) {
Log.e("ML exception", e.message.toString())
}
mlRemoteTranslator.stop()
I get this error here: val result = MLTranslateLanguage.syncGetCloudAllLanguages()
and here: output = mlRemoteTranslator.syncTranslate("SOURCE")
I set the api key like this: MLApplication.getInstance().apiKey = Utils.apiKey
object Utils {
private const val TAG = "Utils"
@JvmStatic
val apiKey: String?
get() {
// get apiKey from AppGallery Connect
val apiKey = "myApiKey"
// need encodeURI the apiKey
return try {
URLEncoder.encode(apiKey, "utf-8")
} catch (e: UnsupportedEncodingException) {
Log.e(TAG, "encode apikey error")
null
}
}}