ear*_*yhe 6 http dart firebase flutter google-cloud-functions
当尝试调用云函数时,我收到“CloudFunctionsException”
重现 重现行为的步骤: - 我来自应用程序的调用是
HttpsCallable _getName;
_getName = CloudFunctions.instance.getHttpsCallable(functionName: 'getName',);
try {
HttpsCallableResult resp = await _getName.call(<String, dynamic>{'name': name,});
Scaffold.of(context).showSnackBar(SnackBar(content: Text("${resp.data}")));
} on CloudFunctionsException catch (e) {
showErrorMessage(context, 'Cloud functions exception with code: ${e.code}, and Details: ${e.details}, with message: ${e.message} ');
} catch (e) {
showErrorMessage(context, e.toString());
}
Run Code Online (Sandbox Code Playgroud)
exports.getName = functions.https.onCall((data, context) => {
return {
"data" : "You hit the call at least!"
};
});
Run Code Online (Sandbox Code Playgroud)
预期行为 在我的响应中,我应该返回数据:“您拨打了测试电话”。相反,我收到错误
附加上下文 当我使用 HTTP 包调用相同的函数并使用“onRequest”在后端接收它时,它可以工作。
exports.getName = functions.https.onCall((data, context) => {
return {
"data" : "You hit the call at least!"
};
});
Run Code Online (Sandbox Code Playgroud)
exports.getName = functions.https.onRequest((request, response) => {
const name = request.query.name || request.body.name;
switch (name) {
case 'Andrew':
request.query.name ? response.send("Na he is the boi Q!") : response.send("Na he is the boi B!");
break;
case 'Brett':
request.query.name ? response.send("Na just wierd! Q") : response.send("Na just wierd! B");
break;
case 'Eddie':
request.query.name ? response.send("My brother but yeah! Q") : response.send("My brother but yeah! B");
break;
case 'James':
request.query.name ? response.send("The biggest! Q") : response.send("The biggest! B");
break;
default:
request.query.name ? response.send("Dunno who that is! Q") : response.send("Dunno who that is! B");
break;
}
});
Run Code Online (Sandbox Code Playgroud)
这是一个模拟应用程序,可以在这里看到 https://github.com/earyzhe/firebase_cloud_functions_play
| 归档时间: |
|
| 查看次数: |
950 次 |
| 最近记录: |