尝试从Flutter调用可调用函数时,使用Firebase Cloud Functions时出现错误。
flutter: caught generic exception
flutter: PlatformException(functionsError, Firebase function failed with exception., {message: NOT FOUND, code: NOT_FOUND})
这是我尝试使用cloud_functions调用云函数的方法:^ 0.4.2 + 3
import 'package:cloud_functions/cloud_functions.dart';
_check(String id) async {
HttpsCallable callable = CloudFunctions.instance
.getHttpsCallable(functionName: 'checkUserFavorites');
try {
final HttpsCallableResult result = await callable.call(
<String, dynamic>{
'id': id,
},
);
print(result.data);
} 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的Cloud Functions Plugin的源代码,才找到了解决方案。
部署Firebase Cloud功能时,可以选择任何首选区域(越接近应用程序越好)。例如
// using DigitalOcean spaces
exports.generateCloudImageUrl = functions
.region('europe-west3')
.https.onCall((reqData, context) => {
...
}
当您想从Flutter应用程序调用此函数时,必须指定区域,否则所有区域都将成为us-central1
默认区域。请参阅示例代码,了解如何使用在特定区域中部署的功能
final HttpsCallable generateCloudImageUrl = new CloudFunctions(region: "europe-west3")
.getHttpsCallable(functionName: 'generateCloudImageUrl');
// NB! if you initialize with 'CloudFunctions.instance' then this uses 'us-central1' as default region!
有关初始化,请参见cloud_function源。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句