gpt4 book ai didi

firebase - 可调用的云函数错误 : Response is missing data field

转载 作者:行者123 更新时间:2023-12-03 02:40:59 29 4
gpt4 key购买 nike

不知道如何从 flutter 中的云函数中获得响应。

我的云功能

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.testDemo = functions.https.onRequest((request, response) => {
return response.status(200).json({msg:"Hello from Firebase!"});
});


我的 flutter 代码
///Getting an instance of the callable function:
try {
final HttpsCallable callable = CloudFunctions.instance.getHttpsCallable(
functionName: 'testDemo',);

///Calling the function with parameters:
dynamic resp = await callable.call();
print("this is responce from firebase $resp");

} on CloudFunctionsException catch (e) {
print('caught firebase functions exception');
print(e.code);
print(e.message);
print(e.details);
} catch (e) {
print('caught generic exception');
print(e);
}


flutter :捕获了 Firebase 函数异常
flutter :内部
flutter :响应缺少数据字段。
flutter :空

最佳答案


exports.testDemo = functions.https.onCall((data, context) => {
return {msg:"Hello from Firebase!"};
});

在云函数中。 Callable不同于 Request

调用函数时需要添加参数:

改变:
 // Calling a function without parameters is a different function!
dynamic resp = await callable.call();

到:
dynamic resp = await callable.call(
<String, dynamic>{
'YOUR_PARAMETER_NAME': 'YOUR_PARAMETER_VALUE',
},
);

如所述 here

然后打印响应:
print(resp.data)
print(resp.data['msg'])

Flutter 示例的 Firebase 函数 herehere

关于firebase - 可调用的云函数错误 : Response is missing data field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57711368/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com