异常:令牌无效或过期。
这是什么错误?我已经设置了 api 密钥。这个令牌代表什么?
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()
我在这里得到这个错误:val result = MLTranslateLanguage.syncGetCloudAllLanguages()
在这里: output = mlRemoteTranslator.syncTranslate("SOURCE")
我这样设置api密钥: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
}
}}