android - 华为移动服务(HMS)异常:云端使用ML kit Real-Time Translation时Token无效或过期?
问题描述
异常:令牌无效或过期。
这是什么错误?我已经设置了 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
}
}}
解决方案
推荐阅读
- haskell - Haskell 98下如何编写多态函数
- php - 如何将图像直接上传到托管在另一台服务器上的子域上?
- regex - 排除文件夹并阻止其他文件夹
- python - 如何在 Tkinter 条目中有占位符?
- spring-boot - 反应式 Spring Security PostAuthorize 注释不起作用
- javascript - 在其他条件下禁用和启用 jQuery 中的提交按钮
- reactjs - 如何模拟由包装器中同一组件上的函数触发的响应?
- c# - Xamarin Slider OnDraw 仅调用一次
- python - Python中两个不同形状的数组的余弦距离是如何计算的?
- r - 使用常用词逐行合并两个数据框