【问题标题】:HTTP trigger Cloud Function in Flutter webFlutter web 中的 HTTP 触发 Cloud Function
【发布时间】:2020-07-26 21:51:45
【问题描述】:

我正在尝试从Flutter 呼叫HTTP trigger Cloud Function。在将参数传递给函数时,我不断在控制台中收到错误。

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!'

【问题讨论】:

  • 能否展示一下你的云函数的代码?
  • 我已编辑问题以包含Cloud Function

标签: python firebase flutter dart google-cloud-functions


【解决方案1】:

我从您的 Google Cloud Console 屏幕截图中看到,您的 HTTP Cloud Function 是用 Python 编写的。

另一方面,在您的 Dart 代码中,您调用的是 Callable Cloud Function

在撰写本文时,仅使用适用于 Node.js 的 Firebase SDK 在 Cloud Functions 上支持 Callable Cloud Functions。

如果您希望用 Python 编写的 HTTP 云函数与您的 Dart 代码一起使用,您需要在云函数本身中实现 ​​protocol for https.onCall

您会找到一个示例 here(未经测试)。


根据您的上述评论进行更新:从您的 Cloud Function 代码中,我们可以确认您没有实现 https.onCall 的协议。

【讨论】:

  • 我在Node.js 8 中创建了一个新的Cloud Function。只更改了函数名称。我仍然收到错误。 Uncaught TypeError:a.functions is not a function。这些Callable Cloud Functions 是否与所有当前可用的Node.js 版本兼容?
  • 支持的 Node.js 版本是 Node.js 8 和 Node.js 10 (Beta)。你是如何创建和部署你的函数的?通过 Firebase CLI?
  • 不,我从谷歌云创建函数,我使用的是 Node.js 8。
  • 这是我认为的问题。如上所述,您需要使用 Firebase SDK for Node.js
  • 谢谢@Renaud...让我也试试https.onCall。因为我写的Cloud Functionspython.
猜你喜欢
  • 2020-08-31
  • 1970-01-01
  • 2020-10-26
  • 1970-01-01
  • 2022-06-15
  • 2020-12-29
  • 2021-08-03
  • 2018-09-20
  • 2019-08-18
相关资源
最近更新 更多