【问题标题】:Flutter - Firebase cloud function callable functions wrong formatFlutter - Firebase 云函数可调用函数格式错误
【发布时间】:2021-08-29 08:50:33
【问题描述】:

我正在尝试使用云函数中的可调用函数修改我的 firestore 数据库...这是我的云函数:

exports.addUserDisplayName = functions.region("europe-west1")
    .https.onCall((data, context) => {
      functions.logger.log("User displayname updated",
          data.userUid, data.displayName);
      admin.firestore().collection("users").doc(data.userUid).update({
        displayName: data.displayName,
      });
      return {
        status: "done",
      };
    });

这是我在 Flutter 应用上调用此云功能的方法:

HttpsCallable addUserDisplayName = FirebaseFunctions.instance.httpsCallable("addUserDisplayName");
      await addUserDisplayName.call({
        'userUid': userCredential!.user!.uid,
        'displayName': "$firstName $lastName",
      },);

但我不知道为什么,每次我尝试调用我的函数时,我都会收到此错误并且没有调用任何内容:

flutter: [firebase_functions/3840] The data couldn’t be read because it isn’t in the correct format.

#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158:18)
<asynchronous suspension>
#2      MethodChannelHttpsCallable.call (package:cloud_functions_platform_interface/src/method_channel/method_channel_https_callable.dart:22:24)
<asynchronous suspension>
#3      HttpsCallable.call (package:cloud_functions/src/https_callable.dart:34:37)
<asynchronous suspension>
#4      AuthProvider.createUser (package:kcount/providers/auth_provider.dart:50:7)
<asynchronous suspension>

你知道为什么吗?

【问题讨论】:

    标签: firebase flutter dart google-cloud-functions callable


    【解决方案1】:

    好的,我发现问题出在区域上……我忘了放.instanceFor(region: 'europe-west1')

    所以我不得不这样做:

    HttpsCallable addUserDisplayName = FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable("addUserDisplayName");
          await addUserDisplayName.call({
            'userUid': userCredential!.user!.uid,
            'displayName': "$firstName $lastName"
          },);
    

    而不是:

    HttpsCallable addUserDisplayName = FirebaseFunctions.instance.httpsCallable("addUserDisplayName");
          await addUserDisplayName.call({
            'userUid': userCredential!.user!.uid,
            'displayName': "$firstName $lastName",
          },);
    

    【讨论】:

      猜你喜欢
      • 2020-07-07
      • 2019-07-29
      • 2019-01-18
      • 1970-01-01
      • 2020-05-29
      • 2020-04-18
      • 2022-01-15
      • 2018-06-09
      • 2021-05-06
      相关资源
      最近更新 更多