【发布时间】:2020-11-24 16:18:00
【问题描述】:
我刚刚开始在 firebase 上使用可调用函数。 我部署了一个函数,它给出了响应 hello world。 当我在本地测试它时效果很好。 现在我正在尝试从 android 应用程序中调用它。 根据这个document,这些可调用函数会自动传递认证数据并反序列化数据以获取函数中的用户id。当我按照上面文档中的建议运行时,我收到一个未经身份验证的错误。 我在应用程序中使用了 Firebase 身份验证来使用谷歌登录。我不想将其公开并保持私有,因此只有用户可以发送请求。有什么方法可以在请求的标头中手动包含身份验证。 这是调用的代码
sendmessage(string)
.addOnCompleteListener {
if (!it.isSuccessful){
val e= it.exception
if(e is FirebaseFunctionsException){
val code =e.code
val details = e.details
Log.d("Firebase error",code.toString()+details.toString())
}
}
else{
Log.d("result obtained",it.result.toString())
}
}
private fun sendmessage(question:String): Task<String> {
val data = hashMapOf(
"question" to question,
"push" to true
)
return functions
.getHttpsCallable("detectIntent")
.call(data)
.continueWith {
val result=it.result?.data as String
result
}
}
【问题讨论】:
标签: android firebase google-cloud-functions