python - Flutter web 中的 HTTP 触发 Cloud Function
问题描述
我正在尝试调用HTTP trigger Cloud Function
from Flutter
。在将参数传递给函数时,我不断在控制台中收到错误。
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'hello_world',
);
final HttpsCallableResult result = await callable.call(
<String, dynamic>{
'message': 'hello world!',
},
);
有人可以指出我做错了什么。使用的Cloud function
是
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 编写的。
另一方面,在您的 Dart 代码中,您正在调用Callable Cloud Function。
在撰写本文时,仅使用适用于 Node.js 的 Firebase SDK 在 Cloud Functions 上支持 Callable Cloud Functions。
如果您希望用 Python 编写的 HTTP Cloud Function 与您的 Dart 代码一起使用,您将需要在 Cloud Function 本身中实现协议。https.onCall
你会在这里找到一个例子(未经测试)。
根据您上面的评论进行更新:从您的 Cloud Function 代码中,我们可以确认您没有为https.onCall
.
推荐阅读
- java - 如何从 JAVA 中的 PriorityQueue 中删除用户定义的类对象
- python - 如何在python中将串口数据写入Text小部件
- c++ - 如何在 C++ 中展开嵌套的 for 循环?
- authentication - OIDC 代表团
- python - Pygame 中的窗口边界不起作用
- node.js - 如何在身份验证路由中忽略 csurf
- c# - 从类库注册 Web API 控制器
- r - R中的数据整理与日期时间列和多个观察
- typescript - 如何根据平台导入模块
- c++ - 如果我使用 ./program_name 执行我的程序,如何在 C++ 中获取文件名
如果我正在执行这样的程序: ./program_name<file_name 如何在 c++ 中获取文件名。
我尝试在主文件和打开文件中使用argue[1],例如。
int main(int argc, char *argv[]){ ifstream file; file.open(a