HTTP trigger Cloud Function in Flutter web

人走茶凉 提交于 2021-01-29 13:08:00

问题


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!',
  },
);

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

回答1:


I see from your screenshot of the Google Cloud Console that your HTTP Cloud Function is written in Python.

On the other hand, in your Dart code, you are calling a Callable Cloud Function.

At the time of writing, Callable Cloud Functions are only supported on Cloud Functions by using the Firebase SDK for Node.js.

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).


Update following your comment above: From you Cloud Function code, we can confirm that you don't implement the protocol for https.onCall.



来源:https://stackoverflow.com/questions/61203117/http-trigger-cloud-function-in-flutter-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!