我有一个Xcode应用程序(用Swift编写),它调用部署在Firebase中的HTTP python函数。它应该得到一个响应,但由于某些原因,当数据为空时,它总是返回。
// swift function in xcode
Functions.functions().httpsCallable("python_callable").call(["ID": ID, "time": String(currentTime)]) { (result, error) in
if error != nil {
//does not enter this
return
}
else {
guard let data = result?.data as? Data else {return}
print(data)
}
}
下面是一个用python编写的google云函数。根据the Google Cloud documentation的说法,Firebase函数使用Flask来处理HTTP请求。
#deployed python Firestore function
import Flask
def python_callable(request):
** processes firestore data **
result = {"text":"example", "score": 100}
return jsonify(data=result)
我知道python_callable函数正在被调用,并且它正在接收请求。然而,似乎无论我做什么,我都无法获得Swift函数来获得响应。它总是接收null。是否存在httpsCallable期望的特定响应格式/ jsonify
是否使用不当?
发布于 2019-02-08 06:53:57
只有使用节点的Firebase SDK才能在云函数上支持callable函数。它们不适用于Python,除非您在函数本身中实现callable协议。如果要调用用python编写的常规HTTP函数,则无法在客户端使用Firebase SDK调用它。
如果您想尝试在服务器端实现该协议,有关可调用器如何工作的文档在这里:https://firebase.google.com/docs/functions/callable-reference
https://stackoverflow.com/questions/54583520
复制相似问题