首页 > 解决方案 > Flutter web 中的 HTTP 触发 Cloud Function

问题描述

我正在尝试调用HTTP trigger Cloud Functionfrom 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!'

标签: pythonfirebaseflutterdartgoogle-cloud-functions

解决方案


我从您的 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.


推荐阅读