【发布时间】:2020-10-16 01:35:21
【问题描述】:
我尝试使用 Flutter 项目中的 cloud_functions 插件调用我的云函数,代码如下:
final HttpsCallable callable = new CloudFunctions(region: "europe-west3")
.getHttpsCallable(functionName: 'helloWorld');
dynamic resp = await callable.call(<String, dynamic>{'id': id, 'chatId': chat.chatId});
并得到以下错误:
ERROR: PlatformException(3840, The data couldn’t be read because it isn’t in the correct format., null)
通过我的研究,我发现当您忘记将区域放在服务器端和客户端时会出现问题,但错误仍然存在。
我也尝试通过成功的http请求:
var parameters = {'id': id, 'chatId': chat.chatId};
var url = "https://europe-west3-{MY_DOMAIN}.cloudfunctions.net/helloWorld";
await http.post(url, body: parameters).then((res) {...}
所以我认为问题出在插件上,我可能忘记了一些东西。有什么想法吗?
云功能(测试):
exports.helloWorld = functions
.region('europe-west3')
.https.onRequest((request, response) => {
try {
response.send('Hello from Firebase!');
} catch (e) {
console.log(e);
throw new functions.https.HttpsError('calc-error', e);
}
});
【问题讨论】:
-
我发现这个question 与你的相似,我认为这个可以帮助你。正如您所提到的,当您不指定区域时会出现问题,所以如果您的云功能位于您用来调用它的同一区域(欧洲西部3),您能否分享一下?
-
@AndieVanille 我更新了问题,您可以看到我已经将区域放入函数中。
-
我在 Callable 函数中遇到了同样的问题
标签: firebase flutter google-cloud-functions