【发布时间】:2021-07-16 22:25:21
【问题描述】:
我最近开始使用 Flutter 和 Firebase 开发应用程序。我使用 Firebase 模拟器来测试身份验证和云功能。我的大部分代码都在 Firebase Cloud Functions 中,我将其用于 Firestore 和 RTDB 的所有 CRUD。在添加一些新功能时,我在我的应用程序中遇到了这个错误。我尝试了很多搜索,但找不到任何解决方案。以下是收到的错误:
An error occured while calling function profile-get
Error Details: null
Message: An internal error has occurred, print and inspect the error details for more information.
Plugin: firebase_functions
Stacktrace: null
我在 Flutter 中的 API 类:
class Api {
Api(this.functions);
final FirebaseFunctions functions;
static Api init() {
FirebaseFunctions functions = FirebaseFunctions.instance;
if (emulator) functions.useFunctionsEmulator(origin: host);
return Api(functions);
}
Future<ApiResult> call(String name, {
Map<String, dynamic> parameters,
}) async {
try {
HttpsCallable callable = functions.httpsCallable(name);
HttpsCallableResult results = await callable.call(parameters);
return ApiResult(new Map<String, dynamic>.from(results.data));
} on FirebaseFunctionsException catch (e) {
print('An error occurred while calling function $name.');
print('Error Details: ${e.details}\nMessage: ${e.message}\nPlugin: ${e.plugin}\nStacktrace: ${e.stackTrace}');
return ApiResult({
'status': 'error',
'message': 'An error occured',
'code': 'unknown'
});
}
}
static String get host => Platform.isAndroid ? 'http://10.0.2.2:2021' : 'http://localhost:2021';
}
我尝试直接从它们的本地 URL 运行这些函数,它们运行良好。
【问题讨论】:
-
能把函数的代码分享给我们吗?你能确认这个函数被调用了吗?对我来说,错误似乎出在函数本身中。
-
问题出在客户端。即使是最简单的功能也不起作用。我尝试使用它们的 URL 调用这些函数并且它们工作正常。但我无法追踪错误。
-
您的函数是否有
onCall或onRequest触发器?那些不一样。如果您可以使用 URL 调用它,则不能在您的应用程序中将其作为可调用函数调用。 -
函数有
onRequest触发器
标签: android ios firebase flutter google-cloud-functions