未处理的异常:PlatformException(functionsError,云函数因异常而失败。,{消息:PERMISSION_DENIED,)

时间:2020-03-31 04:31:57

标签: firebase flutter dart google-cloud-functions

这是我的云功能

exports.addUser = functions.https.onCall((data, context) => {
  console.log(`Hi ${data}`);
  return `Hi there ${data["name"]}`;
});

这是我的代码,点击按钮时会发抖

final HttpsCallable callable = CloudFunctions.instance
        .getHttpsCallable(functionName: 'addUser')
          ..timeout = const Duration(seconds: 30);

 try {
                      final HttpsCallableResult result = await callable
                          .call(<String, dynamic>{"name": "Pritish"});
                      debugPrint(result.data);
                    } on CloudFunctionsException catch (e) {
                      debugPrint('caught generic exception');
                      debugPrint(
                          "${e.message.toString()} ${e.code.toString()} ${e.details.toString()} ${e.toString()}");
                    }

但是我一直在跟踪错误Unhandled Exception: PlatformException(functionsError, Cloud function failed with exception., {message: PERMISSION_DENIED, details: null, code: PERMISSION_DENIED})

我没有访问任何firestore数据库数据,为什么它显示权限错误。我也正在使用firebase之类的其他服务,例如auth,signin, firestore,storage,它们对我来说似乎很好用。我也正确部署了该功能。我还有FCM的其他功能,它们似乎工作正常。 Android for Firebase的设置也正确完成

1 个答案:

答案 0 :(得分:0)

这就是我在网络上使用它的方式。不确定是在移动设备上还是在Web上运行它,但是我很确定您的Firebase配置错误或缺少。

还请注意,您没有为功能提供region

  final FirebaseApp app = await FirebaseApp.configure(
    name: 'XYZ',
    options: const FirebaseOptions(
        apiKey: "AIzaxxxxxxxxxxxxxxxxxxx",
        databaseURL: "https://xyz.firebaseio.com",
        projectID: "xyz",
        storageBucket: "xyz.appspot.com",
        gcmSenderID: "123456789",
        googleAppID: "1:1213123:web:23904832948",
        trackingID: "G-XYZXYZ123"),
  );

  CloudFunctions(app: app, region: "europe-west2")
      .getHttpsCallable(functionName: 'addUser')
      .call({'user': user})
      .catchError((error, stack) => print("Error $error\n$stack"))
      .asStream()
      .listen((event) {
        print("Success ${event.data}");
      });