Flutter Web中的HTTP触发云功能 [英] HTTP trigger Cloud Function in Flutter web
问题描述
我正在尝试从 Flutter
调用 HTTP触发器云函数
.将参数传递给函数时,控制台中不断出现错误.
I am trying to call a HTTP trigger Cloud Function
from Flutter
. I keep getting errors in the console while passing the parameters to the function.
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'hello_world',
);
final HttpsCallableResult result = await callable.call(
<String, dynamic>{
'message': 'hello world!',
},
);
有人可以指出我做错了什么吗?使用的 Cloud函数
是
Can someone point out what is it that I am doing wrong. The Cloud function
used is
def hello_world(request):
request_json = request.get_json()
if request.args and 'message' in request.args:
return request.args.get('message')
elif request_json and 'message' in request_json:
return request_json['message']
else:
return f'Hello World!'
推荐答案
我从您的Google Cloud Console屏幕快照中看到,您的HTTP Cloud Function是用Python编写的.
I see from your screenshot of the Google Cloud Console that your HTTP Cloud Function is written in Python.
另一方面,在Dart代码中,您正在调用可调用云函数.
On the other hand, in your Dart code, you are calling a Callable Cloud Function.
在撰写本文时,仅通过使用Firebase SDK for Node.js在Cloud Functions上支持Callable Cloud Functions.
At the time of writing, Callable Cloud Functions are only supported on Cloud Functions by using the Firebase SDK for Node.js.
如果您希望使用Python编写的HTTP Cloud Function与Dart代码一起使用,则需要实现
If you want an HTTP Cloud Function written in Python to work with your Dart code you will need to implement the protocol for https.onCall
in the Cloud Function itself.
您会找到一个示例此处(未经试用).
You'll find an example here (untested).
按照上面的评论进行更新::从您的Cloud Function代码中,我们可以确认您没有为 https.onCall
实施协议.
Update following your comment above: From you Cloud Function code, we can confirm that you don't implement the protocol for https.onCall
.
这篇关于Flutter Web中的HTTP触发云功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!