有关firebase functions.httpsCallable("findItems").call()用法的文档不足。我已经在firebase上部署了函数:
exports.findItems = functions.https.onCall((data, context) => {
// Grab the long parameter.
functions.logger.log(data.long, typeof data.long);
functions.logger.log(data.lat, typeof data.lat);
const long = parseFloat(data.long);
const lat = parseFloat(data.lat);
functions.logger.log(long, typeof long);
functions.logger.log(lat, typeof lat);
//...
}我在swift中使用functions.httpsCallable("findItems").call()发出请求,但日志总是显示没有正确的参数:

functions.httpsCallable("findItems").call(["lat": userLocation?.latitude, "long": userLocation?.longitude]) { (result, error) in
if let error = error as NSError? {
if error.domain == FunctionsErrorDomain {
let code = FunctionsErrorCode(rawValue: error.code)
let message = error.localizedDescription
let details = error.userInfo[FunctionsErrorDetailsKey]
}
// ...
print(error)
return
}
print(result?.data)
do{
let json = try JSONDecoder().decode([ItemLocation].self, from:result?.data as! Data)
print(json)
}catch{
}
// if let text = (result?.data as? [String: Any])?
//(result?.data as? [String: Any])?["text"] as? String {
//self.resultField.text = text
}您可以在以下网址找到官方文档:https://firebase.google.com/docs/functions/callable
--更新
我已经通过调试尝试了所有的方法,传递的参数总是未定义的,但我遵循官方文档中的每一步。我已经做了更改并使用了onCall,但它仍然不起作用?
发布于 2020-11-06 00:04:05
您混淆了HTTP函数和可调用函数。您的客户端代码试图调用一个可调用的函数,但您的函数本身被定义为HTTP函数。这根本行不通。您应该查看可调用函数的文档,并使用functions.https.onCall而不是functions.https.onRequest来定义您的函数。它们是完全不同的API。
https://stackoverflow.com/questions/64698634
复制相似问题