java - 如何从 Android 调用 Java/Kotlin GCP 云函数
问题描述
我在 kotlin 中编写了一个 http 函数。从 GCP 测试时它工作正常。相同的几行是:
class WinnerDeclaration : HttpFunction {
override fun service(request: HttpRequest?, response: HttpResponse?) {
//code ...
}
}
参考https://firebase.google.com/docs/functions/callable#call_the_function后,我写了这段代码:
private val cloudFunctions = FirebaseFunctions.getInstance()
val data = hashMapOf("uid" to uid)
cloudFunctions
.getHttpsCallable("WinnerDeclaration")
.call(data)
.addOnSuccessListener {
//code ...
}.addOnFailureListener {
it.printStackTrace()
}
但我总是得到这个例外: com.google.firebase.functions.FirebaseFunctionsException: NOT_FOUND
解决方案
可调用 Cloud Functions使用的onCall
协议仅针对 Node.js/Firebase Functions SDK 实现。Google Cloud Functions 支持的任何其他服务器端库都没有实现。
因此,如果您想使用用 Java/Kotlin 编写的可调用 Cloud Functions,您必须自己实现该onCall
协议的服务器端版本。
推荐阅读
- python - 完成某事后如何关闭消息框
- xml - 【需要帮助】XML错误:文档末尾有多余的内容
- javascript - 我需要 12 小时日期/时间格式的正则表达式
- string - 使用 contains 或 equals 方法比较不工作的字符串
- python - 如何在 x 轴上绘制选定的行,在 x 轴上绘制日期时间,在 y 轴上绘制另一列
- sql - 在 SQL 中计算有限和?
- java - 在评估引用另一个工作簿的公式时收到“未链接的书”
- spring - 未配置 SSE 编码器且数据不是字符串?
- rust - 在 Rust 中没有双重匹配语句的情况下将整数与枚举情况匹配
- kaggle - 我的错误:未知扩展 ?Pd 在位置 1